简体   繁体   English

在 VB6 中创建 XML 消息

[英]Creating XML Message in VB6

I want to create an xml document in VB6 similar to this:我想在 VB6 中创建一个与此类似的 xml 文档:

<?xml version="1.0"?>
<AKU_BA_GETMEDBAL_REQUEST xmlns="http://xmlns.aku.edu/ps/sas/schemas/AKU_BA_GETMEDBAL_REQUEST.V1">
  <AKU_BA_MRNO>255-30-98</AKU_BA_MRNO>
    <AKU_BA_SYS_LOCATION>"karachi"</AKU_BA_SYS_LOCATION>
    <AKU_BA_CASHLESS_LOCK>"N"</AKU_BA_CASHLESS_LOCK>
    <AKU_BA_GET_BALANCE>"N"</AKU_BA_GET_BALANCE>
</AKU_BA_GETMEDBAL_REQUEST>

And I am using this code:我正在使用此代码:

Dim objDOM As New MSXML2.DOMDocument30
Dim objNode As MSXML2.IXMLDOMNode
Dim objPerson As MSXML2.IXMLDOMNode
Dim objGrandChildNode As MSXML2.IXMLDOMNode
Dim objAttribute As MSXML2.IXMLDOMAttribute
Dim objElement As MSXML2.IXMLDOMElement
' Create the main xml node
Set objNode = objDOM.createNode(NODE_PROCESSING_INSTRUCTION, "xml", "")
objDOM.appendChild objNode
Set objNode = objDOM.createNode(NODE_ELEMENT, Request1, Request2)
Dim i As Integer
For i = 1 To AttributeCollection.Count
    Set objPerson = objDOM.createNode(NODE_ELEMENT, AttributeCollection.Item(i), "")
    objPerson.Text = AttributeCollection.Item(i + 1)
    objNode.appendChild objPerson
    i = i + 1
Next i
objDOM.appendChild objNode
MsgBox objDOM.xml

Where collections have the data - but it is creating a result like this:集合有数据的地方 - 但它正在创建这样的结果:

<?xml version="1.0"?>
<AKU_BA_GETMEDBAL_REQUEST xmlns="http://xmlns.aku.edu/ps/sas/schemas/AKU_BA_GETMEDBAL_REQUEST.V1">
  <AKU_BA_MRNO xmlns="">255-30-98</AKU_BA_MRNO>
    <AKU_BA_SYS_LOCATION xmlns="">"karachi"</AKU_BA_SYS_LOCATION>
    <AKU_BA_CASHLESS_LOCK xmlns="">"N"</AKU_BA_CASHLESS_LOCK>
    <AKU_BA_GET_BALANCE xmlns="">"N"</AKU_BA_GET_BALANCE>
</AKU_BA_GETMEDBAL_REQUEST>

What can I do because it creates extra xmlns="" on every Person node which I don't want.我该怎么办,因为它在我不想要的每个 Person 节点上创建了额外的xmlns="" Is there any other way to do that?有没有其他方法可以做到这一点?

This behavior is by design.此行为是设计使然。 It occurs only when the parent node references a specified default namespace, and a blank string is supplied as the namespaceURI parameter of the DOMDocument.CreateNode() method that is used to create the child element.仅当父节点引用指定的默认命名空间并且提供空白字符串作为用于创建子元素的 DOMDocument.CreateNode() 方法的 namespaceURI 参数时,才会发生这种情况。 The blank string supplied as the namespaceURI parameter is treated as the explicit default namespace for the child element.作为 namespaceURI 参数提供的空白字符串被视为子元素的显式默认命名空间。

Specify the parent element's namespaceURI as the namespaceURI parameter of the DOMDocument.CreateNode() method to indicate that the parent's namespaceURI applies to the child, and to prevent the generation of the empty namespace declaration for the child element.将父元素的 namespaceURI 指定为 DOMDocument.CreateNode() 方法的 namespaceURI 参数,以指示父元素的 namespaceURI 应用于子元素,并防止为子元素生成空的命名空间声明。

Set objPerson = objDOM.createNode(NODE_ELEMENT, AttributeCollection.Item(i), "urn-FooBar")

For further information and to reproduce it see MS Knowledge Base有关更多信息并重现它,请参阅MS 知识库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM