XmlDocuments.SelectNodes() returns nothing!
Hi.
My XML file does contain "node" element but my code prints nothing:
Code:
string strPath = "./CarList.xml";
string strXpath;
strXpath = "/Name";
XmlNodeList objNodeList;
XmlDocument doc = new XmlDocument();
doc.Load( strPath );
objNodeList = doc.SelectNodes( "/name" );
foreach( XmlNode node in objNodeList )
{
Console.WriteLine( "Here" );
}
Re: XmlDocuments.SelectNodes() returns nothing!
Can you show us some of your xml? If there is a namespace, you may need to use an XmlNameSpaceManager.
http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx
Re: XmlDocuments.SelectNodes() returns nothing!
Quote:
Originally Posted by
HairyMonkeyMan
Can you show us some of your xml? If there is a namespace, you may need to use an XmlNameSpaceManager.
This is a part of my file
Quote:
<Car><CarDetail><Name>Pride</Name><Model>Sedan</Model><ItemsInStock>20</ItemsInStock><Price>6000</Price><Description><Color>Orange</Color><EngSize>1300</EngSize></Description></CarDetail></Car>
Re: XmlDocuments.SelectNodes() returns nothing!
Quote:
Originally Posted by
soheil2
This is a part of my file
more readably:
Quote:
<Car>
<CarDetail>
<Name>Pride</Name>
<Model>Sedan</Model>
<ItemsInStock>20</ItemsInStock>
<Price>6000</Price>
<Description>
<Color>Orange</Color>
<EngSize>1300</EngSize>
</Description>
</CarDetail>
</Car>
Re: XmlDocuments.SelectNodes() returns nothing!
xml and xpath are case sensitive
"/name" and "/Name" are not the same.
Re: XmlDocuments.SelectNodes() returns nothing!
It still prints nothing sir.I replace the string with 'strXpath'.
EDIT:It worked. I just needed to change my strXpath to "//Name".