CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Dec 2013
    Posts
    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" );
    			}

  2. #2
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    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

  3. #3
    Join Date
    Dec 2013
    Posts
    26

    Re: XmlDocuments.SelectNodes() returns nothing!

    Quote Originally Posted by HairyMonkeyMan View Post
    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>

  4. #4
    Join Date
    Dec 2013
    Posts
    26

    Re: XmlDocuments.SelectNodes() returns nothing!

    Quote Originally Posted by soheil2 View Post
    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>

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: XmlDocuments.SelectNodes() returns nothing!

    xml and xpath are case sensitive

    "/name" and "/Name" are not the same.

  6. #6
    Join Date
    Dec 2013
    Posts
    26

    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
  •  





Click Here to Expand Forum to Full Width

Featured