xpath navigation problems
I am new to Xpath and no matter what i try, I cant get XPATH to navigate my xml file.
Any ideas?
Thank you
Peter
<?xml version="1.0" encoding="utf-8"?>
<OurRootClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.NiftyTools.com/WDWEBSVC.xsd">
<Items>
<Item>
<Name>Html download Nifty Tools</Name>
<Address>http://www.niftytools.com</Address>
<Type>HTML Download</Type>
<Status>Unknown</Status>
<StartStop>Stopped</StartStop>
<StartStopTF>false</StartStopTF>
<StatusEnum>MY_STATUS_UNKNOWN</StatusEnum>
<OverallCumulativeCountPass>0</OverallCumulativeCountPass>
<OverallCumulativeCountFail>0</OverallCumulativeCountFail>
<OverallConsecutiveCountPass>0</OverallConsecutiveCountPass>
<OverallConsecutiveCountFail>0</OverallConsecutiveCountFail>
<InitCumulativeCountPass>0</InitCumulativeCountPass>
<InitCumulativeCountFail>0</InitCumulativeCountFail>
<InitConsecutiveCountPass>0</InitConsecutiveCountPass>
<InitConsecutiveCountFail>0</InitConsecutiveCountFail>
<ConnectCumulativeCountPass>0</ConnectCumulativeCountPass>
<ConnectCumulativeCountFail>0</ConnectCumulativeCountFail>
<ConnectConsecutiveCountPass>0</ConnectConsecutiveCountPass>
<ConnectConsecutiveCountFail>0</ConnectConsecutiveCountFail>
<TransferCumulativeCountPass>0</TransferCumulativeCountPass>
<TransferCumulativeCountFail>0</TransferCumulativeCountFail>
<TransferConsecutiveCountPass>0</TransferConsecutiveCountPass>
<TransferConsecutiveCountFail>0</TransferConsecutiveCountFail>
<OtherCumulativeCountPass>0</OtherCumulativeCountPass>
<OtherCumulativeCountFail>0</OtherCumulativeCountFail>
<OtherConsecutiveCountPass>0</OtherConsecutiveCountPass>
<OtherConsecutiveCountFail>0</OtherConsecutiveCountFail>
<ButtonEnabledStartTF>true</ButtonEnabledStartTF>
<ItemButtonEnabledStopTF>false</ItemButtonEnabledStopTF>
<ButtonEnabledResetTF>true</ButtonEnabledResetTF>
<ButtonEnabledRestartTF>true</ButtonEnabledRestartTF>
<ButtonEnabledForceTF>false</ButtonEnabledForceTF>
</Item>
<Item>
<Name>Screen Saver</Name>
<Address>http://infodeli.3com.com/index.htm</Address>
<Type>NT Screen Saver</Type>
<Status>Unknown</Status>
<StartStop>Stopped</StartStop>
<StartStopTF>false</StartStopTF>
<StatusEnum>MY_STATUS_UNKNOWN</StatusEnum>
<OverallCumulativeCountPass>0</OverallCumulativeCountPass>
<OverallCumulativeCountFail>0</OverallCumulativeCountFail>
<OverallConsecutiveCountPass>0</OverallConsecutiveCountPass>
<OverallConsecutiveCountFail>0</OverallConsecutiveCountFail>
<InitCumulativeCountPass>0</InitCumulativeCountPass>
<InitCumulativeCountFail>0</InitCumulativeCountFail>
<InitConsecutiveCountPass>0</InitConsecutiveCountPass>
<InitConsecutiveCountFail>0</InitConsecutiveCountFail>
<ConnectCumulativeCountPass>0</ConnectCumulativeCountPass>
<ConnectCumulativeCountFail>0</ConnectCumulativeCountFail>
<ConnectConsecutiveCountPass>0</ConnectConsecutiveCountPass>
<ConnectConsecutiveCountFail>0</ConnectConsecutiveCountFail>
<TransferCumulativeCountPass>0</TransferCumulativeCountPass>
<TransferCumulativeCountFail>0</TransferCumulativeCountFail>
<TransferConsecutiveCountPass>0</TransferConsecutiveCountPass>
<TransferConsecutiveCountFail>0</TransferConsecutiveCountFail>
<OtherCumulativeCountPass>0</OtherCumulativeCountPass>
<OtherCumulativeCountFail>0</OtherCumulativeCountFail>
<OtherConsecutiveCountPass>0</OtherConsecutiveCountPass>
<OtherConsecutiveCountFail>0</OtherConsecutiveCountFail>
<ButtonEnabledStartTF>true</ButtonEnabledStartTF>
<ItemButtonEnabledStopTF>false</ItemButtonEnabledStopTF>
<ButtonEnabledResetTF>true</ButtonEnabledResetTF>
<ButtonEnabledRestartTF>true</ButtonEnabledRestartTF>
<ButtonEnabledForceTF>false</ButtonEnabledForceTF>
</Item>
<Item>
<Name>Ping Nifty Tools</Name>
<Address>www.niftytools.com</Address>
<Type>Ping</Type>
<Status>Unknown</Status>
<StartStop>Stopped</StartStop>
<StartStopTF>false</StartStopTF>
<StatusEnum>MY_STATUS_UNKNOWN</StatusEnum>
<OverallCumulativeCountPass>0</OverallCumulativeCountPass>
<OverallCumulativeCountFail>0</OverallCumulativeCountFail>
<OverallConsecutiveCountPass>0</OverallConsecutiveCountPass>
<OverallConsecutiveCountFail>0</OverallConsecutiveCountFail>
<InitCumulativeCountPass>0</InitCumulativeCountPass>
<InitCumulativeCountFail>0</InitCumulativeCountFail>
<InitConsecutiveCountPass>0</InitConsecutiveCountPass>
<InitConsecutiveCountFail>0</InitConsecutiveCountFail>
<ConnectCumulativeCountPass>0</ConnectCumulativeCountPass>
<ConnectCumulativeCountFail>0</ConnectCumulativeCountFail>
<ConnectConsecutiveCountPass>0</ConnectConsecutiveCountPass>
<ConnectConsecutiveCountFail>0</ConnectConsecutiveCountFail>
<TransferCumulativeCountPass>0</TransferCumulativeCountPass>
<TransferCumulativeCountFail>0</TransferCumulativeCountFail>
<TransferConsecutiveCountPass>0</TransferConsecutiveCountPass>
<TransferConsecutiveCountFail>0</TransferConsecutiveCountFail>
<OtherCumulativeCountPass>0</OtherCumulativeCountPass>
<OtherCumulativeCountFail>0</OtherCumulativeCountFail>
<OtherConsecutiveCountPass>0</OtherConsecutiveCountPass>
<OtherConsecutiveCountFail>0</OtherConsecutiveCountFail>
<ButtonEnabledStartTF>true</ButtonEnabledStartTF>
<ItemButtonEnabledStopTF>false</ItemButtonEnabledStopTF>
<ButtonEnabledResetTF>true</ButtonEnabledResetTF>
<ButtonEnabledRestartTF>true</ButtonEnabledRestartTF>
<ButtonEnabledForceTF>false</ButtonEnabledForceTF>
</Item>
</Items>
</OurRootClass>
--------
XmlDocument MyXmlDocument = new XmlDocument ();
MyXmlDocument.Load ( "c:\\wdwebsvc.xml" );
XPathNavigator MyXPathNagivator = MyXmlDocument.CreateNavigator ();
MyXPathNagivator.MoveToRoot ();
XPathExpression expr = MyXPathNagivator.Compile ( "//Item" ); // sel all items regardless of where they are in doc
XmlNamespaceManager mngr = new XmlNamespaceManager ( new NameTable() );
mngr.AddNamespace ( "xsd", "http://www.NiftyTools.com/WDWEBSVC.xsd" );
expr.SetContext ( mngr );
XPathNodeIterator MyXPathNodeIterator = MyXPathNagivator.Select ( expr );
Debug.WriteLine ( "got " + MyXPathNodeIterator.Count + " items" );
while ( MyXPathNodeIterator.MoveNext() ) {
// get next item element
XPathNavigator MyXPathNagivatorCurrentChild = MyXPathNodeIterator.Current.Clone ();
// move to 1st child == item name
MyXPathNagivatorCurrentChild.MoveToFirstChild ();
Console.WriteLine ( MyXPathNagivatorCurrentChild.LocalName + " = " + MyXPathNagivatorCurrentChild.Value );
while ( MyXPathNagivatorCurrentChild.MoveToNext () ) {
// get items in child
Console.WriteLine ( "\t" + MyXPathNagivatorCurrentChild.LocalName + " = " + MyXPathNagivatorCurrentChild.Value );
}
Console.WriteLine ( "" );
} // next child

