复制代码
- <?xml version="1.0" encoding="GB2312"?>
- <n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="1.xsd">
- <string a=" s
- s "/>
- <normalizedString a=" n
- n "/>
- <token a=" t
- t "/>
- </n>
复制代码
- <?xml version="1.0" encoding="GB2312"?>
- <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xs:element name="n">
- <xs:complexType>
- <xs:all>
- <xs:element name="string">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="a" type="xs:string"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- <xs:element name="normalizedString">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:normalizedString">
- <xs:attribute name="a" type="xs:normalizedString"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- <xs:element name="token">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:token">
- <xs:attribute name="a" type="xs:token"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- </xs:all>
- </xs:complexType>
- </xs:element>
- </xs:schema>
复制代码
- Option Explicit
- Dim oDOMDocument, oXSD, oXMLDOMElement, s
- Set oXSD = CreateObject("Msxml2.XMLSchemaCache.6.0")
- oXSD.add "", "1.xsd"
- Set oDOMDocument = CreateObject("Msxml2.DOMDocument.6.0")
- oDOMDocument.setProperty "NormalizeAttributeValues", "True"
- oDOMDocument.schemas = oXSD
- oDOMDocument.load "1.xml"
- If oDOMDocument.parseError.errorCode <> 0 Then '如果加载xml出错
- MsgBox oDOMDocument.parseError.reason & vbLf & _
- "第 " & oDOMDocument.parseError.line & " 行"
- WScript.Quit()
- End If
- MsgBox oDOMDocument.xml
- Set oXMLDOMElement = oDOMDocument.documentElement '根节点
- s = oXMLDOMElement.SelectNodes("string")(0).getAttribute("a")
- MsgBox s & vbLf & Len(s)
- s = oXMLDOMElement.SelectNodes("normalizedString")(0).getAttribute("a")
- MsgBox s & vbLf & Len(s)
- s = oXMLDOMElement.SelectNodes("token")(0).getAttribute("a")
- MsgBox s & vbLf & Len(s)
欢迎光临 批处理之家 (http://bathome.net./) | Powered by Discuz! 7.2 |