Excel VB和XML命名空间命名约定
假设在下面的示例中gfx是根元素,xmlns:xsi和xsi:noNameSpaceSchemaLocation是否被视为根的属性,如果是,如何使用Excel VB语法分配它们?使用下面的代码,它们的显示顺序是相反的Excel VB和XML命名空间命名约定,excel,xml,Excel,Xml,假设在下面的示例中gfx是根元素,xmlns:xsi和xsi:noNameSpaceSchemaLocation是否被视为根的属性,如果是,如何使用Excel VB语法分配它们?使用下面的代码,它们的显示顺序是相反的 Dim doc As New MSXML2.DOMDocument60 Dim root As IXMLDOMElement Dim rootAttrib1 As IXMLDOMAttribute, rootAttrib2 As IXMLDOMAttribute
Dim doc As New MSXML2.DOMDocument60
Dim root As IXMLDOMElement
Dim rootAttrib1 As IXMLDOMAttribute, rootAttrib2 As IXMLDOMAttribute
' DECLARE ROOT AND CHILDREN '
Set root = doc.createElement("gfx")
doc.appendChild root
Set rootAttrib1 = doc.createAttribute("xmlns:xsi")
rootAttrib1.Value = "http://www.w3.org/2001/XMLSchema-instance"
root.setAttributeNode rootAttrib1
Set rootAttrib2 = doc.createAttribute("xsi:noNamespaceSchemaLocation")
rootAttrib2.Value = "Gfx-ME12.xsd"
root.setAttributeNode rootAttrib2
期望输出
<?xml version="1.0" encoding="UTF-8"?>
<gfx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Gfx-ME12.xsd">
实际产量
<?xml version="1.0" encoding="UTF-8"?>
<gfx xsi:noNamespaceSchemaLocation="Gfx-ME12.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
xml属性的顺序并不重要。
在xml信息集中没有属性顺序。谢谢。运行我的代码,另一端的解析器似乎很好地接受了它