3

XML file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>    
<content>
      <FingerPrintUserDetails>
        <UserID>e57645</UserID>
        <UserName>Jill</UserName>
        <FPData>AQAAABQAAAD0AAAAAQASAAEAWgAAAAAA8AAAAHfrWpB6BHZBL10voxpdxu2Km5XVNh*oUNC80Rvpql3RhlqOiBPeet6iRPwb/BdN1fCF4Y/WHbQ40*mqoUKqilgN7bUqNuXP7M299HUWtoAGEO3nDKXXAnHd7dgytZbmHVv*mRBPJDSRw9VY/R1yOIu2cCDlLM*F8Q1lvTfMFDdfwNZynI0e2ZauCF58f0UX56XLFBallaAauxP5mvvhUmcmc6ITg7RhH9wc4181kgPjCuZg38pQepE5U07XIa3hQP8fwxPzdprifXECgB1Z3pTXWQP0q4ZD0Inlbq6Gszo1ucPrhQA0jYQRXtJUVuyBeg</FPData>
        <Address>Pune</Address>
        <ContactNo>848488484884</ContactNo>
      </FingerPrintUserDetails>


      <FingerPrintUserDetails>
        <UserID>444</UserID>
        <UserName>John</UserName>
        <FPData>AQAAABQAAADkAAAAAQASAAEAZAAAAAAA4AAAAPLnmQ8FymAAHWYutR5pdtYvfDVmjsqLeli8tOSTFAtw6AkfA0r8XwrMzp9jFZJI7DlBk4G94BMq55gPEG7uBLZUNYrvhv0jDlDFMOjWGJ9RoWekFveTC*oZ7Tq/xmxuvY6FzLHVo*xzdKQI73Y0f9/eeMC0OgqnbQ3I0IP6cTkkKnTUZJOXKr7IFPHkjJAvCDmU7ec4vG50JHdBJIObmbzVcO0huTUQyE7CR1qYkUjmNFKgVKWPLRupEk4l/Ek0BuAba*9JlhBVUHzZuKbDQLc9lTFwevAgDuuAwxfZaLS*</FPData>
        <Address>nagpur</Address>
        <ContactNo>464645763</ContactNo>
      </FingerPrintUserDetails>


      <FingerPrintUserDetails>
        <UserID>5555</UserID>
        <UserName>Jack</UserName>
        <FPData>AQAAABQAAAAEAQAAAQASAAEAZAAAAAAA9AAAAPz5mQO3uTeXLfU5Mb74XbCX5rERGZFPQMVG1vPpX87306O5oURlYiIe5dasJ2S8NlBZu2UU3zaUpNnB7viYDB6*wfFlgtopn/WdbXW0Yhik3hj8nDreEmaK12To8qfAJx2ooq43i0wBIL*0Jkba*QpHIprSajrhnCg1PjOLMP37sEauJUwXJaoDR/PPQYIxTFE5kf8xzGlJmqiGejD*Y8R3ewU9yIrxkdQ0S//LCdacULt2QvS/I3APo/j0FAgSCOU3SBLdDL6UBPD4fLeEzo7uUIW8gUMThzZX*u2iUuNwJdqWC2NsFtWkUWt03sz3xYQpR8pLA4vrsUmldzUMWe8</FPData>
        <Address>beed</Address>
        <ContactNo>5745745747</ContactNo>
      </FingerPrintUserDetails>


    </content>

C#:

XmlDocument doc = new XmlDocument();
doc.Load("E://BioEnable_Project//fp_project_using_xml//fp_project_using_xml//Capture_Data.xml");
XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("FPData");
foreach(XmlElement node in nodes)
{
    MessageBox.Show(node.Value);
}   

I have to check FPData value on each node..i use above code but not getting..

1
  • What happens if you try? Is there an exception? If so, what is the message? What line is the exception thrown in? Please don't let us guess around on details that you could easily add to your question. Commented Sep 10, 2012 at 11:36

4 Answers 4

3

In your XPath, provide the full path to the node.

XmlNodeList nodes = root.SelectNodes("/content/FingerPrintUserDetails/FPData");

What is happening is that there is no direct FPData node under the document root.

Sign up to request clarification or add additional context in comments.

5 Comments

@lax - Forgot to start from the root. Added a / at the path start.
i have to get FPData where USerID="e57645" how will be my code where UserID coming from textbox
@lax - That really is a different question from the above. But this can be done with xpath as well: "/content/FingerPrintUserDetails[UserID = 'e57645']/FPData". How you construct the XPath I leave to you...
@lax - Don't know what that means. I tested the above XPath with the XML file you posted and got a single FPData node.
i used in my code like this XmlNodeList nodes = root.SelectNodes("/content/FingerPrintUserDetails['" + txtUserId.Text.Trim() + "']/FPData");
2
XmlNodeList nodes = root.SelectNodes("content/FingerPrintUserDetails");

it will return array of FingerPrintUserDetails, then find FPData in them

XmlNodeList res = nodes[index].SelectNodes("FPData");

Comments

2

Using LINQ to XML:

 XDocument doc = XDocument.Load("XmlFilePath");
 var selectors = from elements in doc.Elements("content").Elements("FingerPrintUserDetails")
                 select elements;

foreach (var element in selectors)
 {
    MessageBox.Show(element.Element("FPData").Value);
 }

Comments

1
XmlDocument doc = new XmlDocument();
doc.Load("E://BioEnable_Project//fp_project_using_xml//fp_project_using_xml//Capture_Data.xml");
XmlNodeList lst =  doc.GetElementsByTagName("FingerPrintUserDetails");

foreach (XmlElement elem in lst)
{
    XmlNode pfData = doc.GetElementsByTagName("FPData")[0];
    MessageBox.Show(pfData.Value);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.