VB6を削除VB6のDOMDocumentは、特定のコメントを検索し、Win8.1 のMicrosoft XML v3.0の上
私はVB6を使用してXMLファイル内の要素を検索することができ、無駄-Iで検索しましたが、私は検索する方法を見つけ出すことはできませんxmlファイル内の特定のコメントを削除して削除します。
I素晴らしいVB6 XML tutorial見出さ - 私が働いているコードの種類の例として、ツリービュー/ Webブラウザーコントロールにノードをロードするために、次のいくつかのサンプルコード:
Private Sub cmdPopulate_Click()
Dim objPeopleRoot As IXMLDOMElement
Dim objPersonElement As IXMLDOMElement
Dim tvwRoot As Node
Dim X As IXMLDOMNodeList
Set m_objDOMPeople = New DOMDocument
'this can stop the m_objDOMPeople object from looking
'for external files which in our case are the people.dtd
'and the people.xsl files - set this to true if you want
'the parser to look for the external files
m_objDOMPeople.resolveExternals = True
'this can stop the m_m_objDOMPeople from validating the XML file
'against the people.dtd file - set this to true if you want validation to
'occur
m_objDOMPeople.validateOnParse = True
'load the XML into the dom document, using a string containing
'the XML location
m_objDOMPeople.async = False
Call m_objDOMPeople.Load(m_strXmlPath)
'check that the load of the XML document was successful
If m_objDOMPeople.parseError.reason <> "" Then
' there has been an error with the loaded XML - show the reason
MsgBox m_objDOMPeople.parseError.reason
Exit Sub
End If
'get the root element of the XML - bypassing the comments, PI's etc
Set objPeopleRoot = m_objDOMPeople.documentElement
'Now lets populate the treecontrol from the DOMDocument
'Set Treeview control properties.
tvwPeople.LineStyle = tvwRootLines
tvwPeople.Style = tvwTreelinesPlusMinusText
tvwPeople.Indentation = 400
'check if the treeview has already been populated - if so
'remove the root, which removes everything.
If tvwPeople.Nodes.Count > 0 Then
tvwPeople.Nodes.Remove 1
End If
' add a child to the root node of the TreeView
Set tvwRoot = tvwPeople.Nodes.Add()
tvwRoot.Text = objPeopleRoot.baseName
'iterate through each element in the dom to fill the tree,
'which in itself iterates through each childNode of that
'element(objPersonElement) to drill down into its childNodes
For Each objPersonElement In objPeopleRoot.childNodes
populateTreeWithChildren objPersonElement
Next
webTarget.Navigate m_strXmlPath
cmdDelete.Enabled = True
cmdClear.Enabled = True
End Sub
IがCOMMENT_NODE発見した - w3schoolsに8私は事前にVB6で
おかげでそれを使用する方法がわからないです
EDIT:使用Bobのコード
私はそれを以下のように呼びます - これは正しいですか?それは繰り返され、各.nodetypeのコメントを見つけるようです。私はこれが演算子のエラーだと確信しています - 誤ってDeleteTargetCommentsを呼び出す場合 - 間違ったオブジェクトを渡す - 正しい方法は何ですか?
Private m_objDOMPeople As DOMDocument
Private Sub cmdRemoveComments_Click()
' DeleteTargetComments DOM.documentElement
Dim objPeopleRoot As IXMLDOMElement
Set objPeopleRoot = m_objDOMPeople.documentElement
DeleteTargetComments objPeopleRoot
End Sub
この質問でXPATHがどのように使用されているかを見てください。http://stackoverflow.com/questions/8836590/vb6-select-a-single-node-using-xpath-with-backslashes-underscores – jac
あなたは応答しています - それをチェックします – beginAgain
これは正しいように見えますが、必要以上に「チャット」があります(別に宣言され、設定された変数は必要ありません)。なぜそれがうまくいかないのか分かりません。 – Bob77