GetElementsByTagName 返回空列表
GetElementsByTagName("track") 当存在一个“track”元素时不返回任何元素
test.vbs
Dim oXML
Set oXML = CreateObject("Msxml2.DOMDocument.6.0")
oXML.async = True
oXML.onreadystatechange = getRef("ParseXML")
oXML.Load("http://musicbrainz.org/ws/1/track/?type=xml&limit=1&artist=the%20archies&title=sugar%20sugar")
Sub ParseXML()
If oXML.readyState <> 4 Then Exit Sub
If oXML.parseError.errorCode <> 0 Then Exit Sub
MsgBox(oXML.documentElement.GetElementsByTagName("track").length)
MsgBox(oXML.documentElement.GetElementsByTagName("*").length)
MsgBox(oXML.xml)
End Sub
MsgBox("Wait...") ' Keeps oXML in memory
GetElementsByTagName("track") 输出 >0
GetElementsByTagName("*") 输出 10
oXML.xml 输出源 XML
<?xml version="1.0" encoding="UTF-8" ?>
<metadata xmlns="http://musicbrainz.org/ns/mmd-1.0#" xmlns:ext="http://musicbrainz.org/ns/ext-1.0#">
<track-list offset="0" count="180">
<track id="5153eb2d-c37e-43eb-8340-6dcafaf3ebc9" ext:score="100">
<title>Sugar, Sugar</title>
<duration>168186</duration>
<artist id="623d5f3f-3093-4711-881f-ed33eda10882">
<name>The Archies</name>
</artist>
<release-list>
<release type="Compilation" id="4930d2a7-3b60-41b2-8511-a678bce1d9fb">
<title>Fetenhits: Oldies (disc 1)</title>
<track-list offset="16" count="20" />
</release>
</release-list>
</track>
</track-list>
</metadata>
如何获取“track”元素列表?
GetElementsByTagName("track") returns no elements when there is one "track" element
test.vbs
Dim oXML
Set oXML = CreateObject("Msxml2.DOMDocument.6.0")
oXML.async = True
oXML.onreadystatechange = getRef("ParseXML")
oXML.Load("http://musicbrainz.org/ws/1/track/?type=xml&limit=1&artist=the%20archies&title=sugar%20sugar")
Sub ParseXML()
If oXML.readyState <> 4 Then Exit Sub
If oXML.parseError.errorCode <> 0 Then Exit Sub
MsgBox(oXML.documentElement.GetElementsByTagName("track").length)
MsgBox(oXML.documentElement.GetElementsByTagName("*").length)
MsgBox(oXML.xml)
End Sub
MsgBox("Wait...") ' Keeps oXML in memory
GetElementsByTagName("track") outputs 0
GetElementsByTagName("*") outputs 10
oXML.xml outputs the source XML
<?xml version="1.0" encoding="UTF-8" ?>
<metadata xmlns="http://musicbrainz.org/ns/mmd-1.0#" xmlns:ext="http://musicbrainz.org/ns/ext-1.0#">
<track-list offset="0" count="180">
<track id="5153eb2d-c37e-43eb-8340-6dcafaf3ebc9" ext:score="100">
<title>Sugar, Sugar</title>
<duration>168186</duration>
<artist id="623d5f3f-3093-4711-881f-ed33eda10882">
<name>The Archies</name>
</artist>
<release-list>
<release type="Compilation" id="4930d2a7-3b60-41b2-8511-a678bce1d9fb">
<title>Fetenhits: Oldies (disc 1)</title>
<track-list offset="16" count="20" />
</release>
</release-list>
</track>
</track-list>
</metadata>
How do I get a list of "track" elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 XML 文档正在使用默认命名空间。也许您应该使用 getElementsByTagNameNS 来代替。
Your XML document is using a default namespace. Maybe you should use getElementsByTagNameNS instead.