我在分类XML查询时发现的大多数例子并不包括一个名称空间。 其中有些人这样做,但我找不到在有名字空间时进行询问和分类的任何例子。
<Search xmlns="http://whatever.whatever.com/gg/whatever">
<BinSet Type="Category">
<Bin>
<BinName>Clothing</BinName>
<BinItemCount>804</BinItemCount>
<BinParameter>
<Name>Category</Name>
<Value>Women s Apparel</Value>
</BinParameter>
</Bin>
<Bin>
<BinName>Tools</BinName>
<BinItemCount>126</BinItemCount>
<BinParameter>
<Name>Category</Name>
<Value>Tools, handtools and hardware</Value>
</BinParameter>
</Bin>
</BinSet>
</Search>
I don t have any control of the XML, so I have to deal with the namespace. Also, There are approximately 50 of these records in the XML and it is only part of a much larger XML file.
Dim nsuri as string = "http://whatever.whatever.com/gg/whatever"
Dim xpath as string = "dd:Search/dd:BinSet[Type="Category"]/*"
Dim nav As XPathNavigator = doc.CreateNavigator()
Dim exp As XPathExpression = nav.Compile(xpath)
Dim nsmgr As New XmlNamespaceManager(nav.NameTable)
nsmgr.AddNamespace("dd", nsuri)
exp.SetContext(nsmgr)
exp.AddSort("BinParameter/Value", XmlSortOrder.Ascending, XmlCaseOrder.UpperFirst, "en-US", XmlDataType.Text)
now process in sorted order
Dim iterator As XPathNodeIterator = nav.Select(exp)
While iterator.MoveNext
Dim nav2 As XPathNavigator = iterator.Current.Clone
nav2.MoveToFirstChild()
Debug.WriteLine(nav2.Value)
End While
我所看到的所有例子都表明,如何把眼下的儿童节点划为一,例如我的XML。 但是,我需要所有这些信息,我需要把本巴拉参数/瓦莱诺德区分开来。 我尽一切可能想......
最后一点值得注意,在说并做所有事情时,我没有真正谨慎地利用XPathNodeIterator或XPathNavigator。 此前,我正在归还一位名叫XmlNodeList的XmlNodeList的所有记录,而我经常呼吁不要把这个名字编成联系,如:
<a href="mypage.aspx?si=Tools">Tools, handtools and hardware (126)</a>
<a href="mypage.aspx?si=Clothing">Women s Apparel (804)</a>
是否有任何人知道如何用名称空间将这种XML打上“Value”的被nes子?
此外,如果你知道以XmlNodeList或其他人来回报这种结果的最快方式。 净物体,以便我能够接触到所有价值:BinName, BinItemCount, 姓名和价值? I m 不熟悉XPathNavigator或XPathNodeIterator。
谢谢。