将属性添加到XML Element

时间:2016-02-25 18:52:20

标签: xml vb6 attributes xmldom

我正在尝试向XML Element添加属性。我似乎无法让它发挥作用。

Public Sub fnWriteXML(DATA)
  Dim oDoc As New MSXML2.DOMDocument60
  Dim oNode As IXMLDOMProcessingInstruction
  Dim sDC As String
  Dim xAtt1 As IXMLDOMAttribute
  Dim xAtt2 As IXMLDOMAttribute
  Dim xAtt3 As IXMLDOMAttribute
  Dim xAtt4 As IXMLDOMAttribute

  sDC = """

  'oDoc.async = False
  oDoc.validateOnParse = False
  oDoc.resolveExternals = False
  oDoc.preserveWhiteSpace = True
  'Processing Instruction
  Set oNode = oDoc.createProcessingInstruction("xml", "version='1.0'")
  oDoc.appendChild(oNode)
  Set oNode = Nothing

  ' Create Top Level kfx
  Dim XMLREL As IXMLDOMElement
  Set XMLREL = oDoc.createElement("cus.XMLRELEASE")
  'Add attribute
  Set xAtt1 = oDoc.createAttribute("xmlns:cus")
  xAtt1.Value = "http://www.myurl.com"
  xAtt1.appendChild(XMLREL)
  oDoc.appendChild(XMLREL)

  oDoc.Save("E:\TestXML\Test.xml")
End Sub

以上示例中的行:

xAtt1.appendChild(XMLREL)

类型不匹配失败。

如何向元素添加一个或多个属性?我正在从源应用程序中的一系列值构建此XML。

0 个答案:

没有答案