1

我正在尝试阅读以下文件(部分显示)

<?xml version="1.0" encoding="utf-8"?>
 <asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd"
 manifestVersion="1.0"
 xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"
 xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
 xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1"
 xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2"
 xmlns="urn:schemas-microsoft-com:asm.v2"
 xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
 xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
 xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <assemblyIdentity name="program.application" version="4.0.0.27077" publicKeyToken="8f99fe9fddfae125e" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />

我有

Dim manifestFile As String = webClient.DownloadString(location)
Dim xdoc As New Xml.XmlDocument()
xdoc.LoadXml(manifestFile)

我努力了

xdoc.SelectSingleNode("//asmv1:assemblyIdentity")
xdoc.SelectSingleNode("//assemblyIdentity")

Dim nsSys As Xml.XmlNamespaceManager = New Xml.XmlNamespaceManager(xdoc.NameTable)
nsSys.AddNamespace("def", "urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd")
xdoc.SelectSingleNode("//asmv1:assemblyIdentity",ns)
xdoc.SelectSingleNode("//assemblyIdentity",ns)
xdoc.SelectSingleNode("//def:assemblyIdentity",ns)

全部返回Nothing

选择<assemblyIdentity>节点的正确路径是什么?

注意我不能使用 LinqToXml

谢谢

4

1 回答 1

2

假设我关闭标签 - 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
    <asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <assemblyIdentity name="program.application" version="4.0.0.27077" publicKeyToken="8f99fe9fddfae125e" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
    </asmv1:assembly>

以下对我有用:

Dim doc As New XmlDocument()
Dim nsmgr As New XmlNamespaceManager(doc.NameTable)

doc.Load("c:\temp\temp2.xml")
nsmgr.AddNamespace("asmv1", "urn:schemas-microsoft-com:asm.v1")

Dim node As XmlNode = doc.SelectSingleNode("//asmv1:assemblyIdentity", nsmgr)
MessageBox.Show(node.OuterXml)

并返回:

<assemblyIdentity name="program.application" version="4.0.0.27077" publicKeyToken="8f99fe9fddfae125e" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />

<assemblyIdentity>节点引用 asmv1 命名空间,因此需要将其添加到 XMLNamespaceManager

于 2013-06-12T15:34:52.420 回答