Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. how to fetch child nodes of parent node in XML .. using c#...

how to fetch child nodes of parent node in XML .. using c#...

Scheduled Pinned Locked Moved XML / XSL
csharphtmlcomxmltutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vishnu Narayan Mishra
    wrote on last edited by
    #1

    hello every one... I am tried to retrieve a node FieldsToSupport/FieldToSuport in a xml.. Following is the structure of my xml file.....there can be multiple into in a . Also can be multiple.. ------------------------------------------------------------ 0 1.0.1 e7dfee93-14f0-4775-baef-c7246dfae902 2007-10-25T11:47:10.515625+05:30 SUBHASH\Login Subhash C:\Documents and Settings\Login Subhash\Desktop\iframeCopy.html Updating Adding New Row 3 Blank Blank NewField1 15b85c2b-83ca-44ec-8741-22a4dc64f64d http://careers.msn.com/ Careers & Jobs <A href="http://careers.msn.com">Careers & Jobs</A> Blank Blank Screen2 97d5c477-a5f4-4496-8084-19a537d85e29 http://slate.com/ Slate Magazine <A href="http://slate.com">Slate Magazine</A> label3 172.0934 ------------------------------------------------------------ and following is my code in c#. I am try to fetch node

    L 1 Reply Last reply
    0
    • V Vishnu Narayan Mishra

      hello every one... I am tried to retrieve a node FieldsToSupport/FieldToSuport in a xml.. Following is the structure of my xml file.....there can be multiple into in a . Also can be multiple.. ------------------------------------------------------------ 0 1.0.1 e7dfee93-14f0-4775-baef-c7246dfae902 2007-10-25T11:47:10.515625+05:30 SUBHASH\Login Subhash C:\Documents and Settings\Login Subhash\Desktop\iframeCopy.html Updating Adding New Row 3 Blank Blank NewField1 15b85c2b-83ca-44ec-8741-22a4dc64f64d http://careers.msn.com/ Careers & Jobs <A href="http://careers.msn.com">Careers & Jobs</A> Blank Blank Screen2 97d5c477-a5f4-4496-8084-19a537d85e29 http://slate.com/ Slate Magazine <A href="http://slate.com">Slate Magazine</A> label3 172.0934 ------------------------------------------------------------ and following is my code in c#. I am try to fetch node

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Well I have some suggestions for you. First I recommend, it's what I use, www.w3schools.com as an excellent reference for things like XPath etc. Second, find yourself a method of testing XPath statements before you try to integrate them into code. I mean you just type a statement and execute it in some environment to see that you obtain the node or node set desired. There might be something you can get for free and it's not that difficult to write a little command line utility or even a Windows Forms application for testing XPath statements. Lastly, when you want to create a paramaterized XPath statement don't use string concatination, use String.Format(...) with format strings that have placeholders for the parameters. It's far simpler to get the XPath statement syntax correct when you do that. Let's use your statement as an example: "/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='"+strScreenId+"']"; The format string would be: "/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='{0}']"; then use it in String.Format and pass the parameter to fill in the placeholder. Now to your problem. You XPath statement syntax is incorrect, there should be no path separator before the expression ScreenToSupport/[ScreenUniqueId should be ScreenToSupport[ScreenUniqueId

      V 1 Reply Last reply
      0
      • L led mike

        Well I have some suggestions for you. First I recommend, it's what I use, www.w3schools.com as an excellent reference for things like XPath etc. Second, find yourself a method of testing XPath statements before you try to integrate them into code. I mean you just type a statement and execute it in some environment to see that you obtain the node or node set desired. There might be something you can get for free and it's not that difficult to write a little command line utility or even a Windows Forms application for testing XPath statements. Lastly, when you want to create a paramaterized XPath statement don't use string concatination, use String.Format(...) with format strings that have placeholders for the parameters. It's far simpler to get the XPath statement syntax correct when you do that. Let's use your statement as an example: "/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='"+strScreenId+"']"; The format string would be: "/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='{0}']"; then use it in String.Format and pass the parameter to fill in the placeholder. Now to your problem. You XPath statement syntax is incorrect, there should be no path separator before the expression ScreenToSupport/[ScreenUniqueId should be ScreenToSupport[ScreenUniqueId

        V Offline
        V Offline
        Vishnu Narayan Mishra
        wrote on last edited by
        #3

        hello sir the way you tried to explain me is excellent.. But I am did'nt get you point 'then use it in String.Format and pass the parameter to fill in the placeholder.' How we pass parameter into String.Format pls tell m? Thanks a lot

        L 1 Reply Last reply
        0
        • V Vishnu Narayan Mishra

          hello sir the way you tried to explain me is excellent.. But I am did'nt get you point 'then use it in String.Format and pass the parameter to fill in the placeholder.' How we pass parameter into String.Format pls tell m? Thanks a lot

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          Vishnu Narayan Mishra wrote:

          How we pass parameter into String.Format pls tell m?

          I don't think I understand your question. You have read the documentation[^] yes?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups