0
$ns = New-Object System.Xml.XmlNamespaceManager($books.NameTable)
などを使用してXML名前空間マネージャを作成しようとしましたが、XMLドキュメント$books
があります。私はそれ以来何が間違っているのかよく分かりません。 SelectSingleNode()
を使用して、必要な特定のノードのXMLドキュメントを検索しようとしていますが、すべてのXPathクエリがnullを返します。ネームスペース問題 - nullを返すすべてのXPathクエリ
ここでは、XML文書のビットがあります:
<ernm:NewReleaseMessage xmlns:ernm="http://ddex.net/xml/ern/341" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" LanguageAndScriptCode="en" MessageSchemaVersionId="/ern/341" xs:schemaLocation="http://ddex.net/xml/ern/341 http://ddex.net/xml/ern/341/release-notification.xsd">
<MessageHeader>
<MessageId>123123</MessageId>
<MessageRecipient>
<PartyId>567567</PartyId>
<PartyName>
<FullName>John Smith</FullName>
</PartyName>
</MessageRecipient>
</MessageHeader>
</ernm:NewReleaseMessage>
はまた、ここで私はSelectSingleNode()
が正常に機能し得るために、これまで試したもののビットがあります:
[xml]$books = Get-Content xmlpath.xml
$ns = New-Object System.Xml.XmlNamespaceManager($books.NameTable)
$ns.AddNamespace("ns", $books.DocumentElement.NamespaceURI)
$books.SelectSingleNode("//newreleasemessage", $ns) #returns null
$books.SelectSingleNode("//ns:newreleasemessage", $ns) #returns null
$books.SelectSingleNode("//ernm:newreleasemessage", $ns) #returns null
$books.SelectSingleNode("//xmlns:newreleasemessage", $ns) #returns null
$books.SelectSingleNode("//xml:newreleasemessage", $ns) #returns null
私はしましたnewreleasemessage
以外のノードも試してみましたが、まだ空白に戻ってしまったので、私が試したことのいくつかの例を提供したかったのです。ここで名前空間を使用する正しい方法は何ですか?
スウィートロード私は愚かな気がします。ありがとう、あなたのupvoteを持っています。なぜ、それはすべての単一のxpathの紹介の最上部に貼り付けられていないのですか? –
これは、ここ数年、大文字と小文字を区別しない言語で書かれた人にとっては問題であり、少数派です。 –