-
December 11th, 2013, 05:38 AM
#1
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" );
}
-
December 11th, 2013, 06:31 AM
#2
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
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010
-
December 11th, 2013, 11:32 PM
#3
Re: XmlDocuments.SelectNodes() returns nothing!
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
<Car><CarDetail><Name>Pride</Name><Model>Sedan</Model><ItemsInStock>20</ItemsInStock><Price>6000</Price><Description><Color>Orange</Color><EngSize>1300</EngSize></Description></CarDetail></Car>
-
December 12th, 2013, 12:10 AM
#4
Re: XmlDocuments.SelectNodes() returns nothing!
Originally Posted by soheil2
This is a part of my file
more readably:
<Car>
<CarDetail>
<Name>Pride</Name>
<Model>Sedan</Model>
<ItemsInStock>20</ItemsInStock>
<Price>6000</Price>
<Description>
<Color>Orange</Color>
<EngSize>1300</EngSize>
</Description>
</CarDetail>
</Car>
-
December 13th, 2013, 08:51 AM
#5
Re: XmlDocuments.SelectNodes() returns nothing!
xml and xpath are case sensitive
"/name" and "/Name" are not the same.
-
December 17th, 2013, 03:38 AM
#6
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".
Last edited by soheil2; December 17th, 2013 at 03:45 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|