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. C#
  4. one more c# xml issue

one more c# xml issue

Scheduled Pinned Locked Moved C#
helptutorialquestioncsharpxml
8 Posts 5 Posters 1 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.
  • L Offline
    L Offline
    laziale
    wrote on last edited by
    #1

    hello once again today - I do have one more question and I hope that someone can help me one more time today again. I have an xml document similar to this one:

    <person id="1">
    <first>John</first>
    <last>Smith</last>
    </person>
    <person id="2">
    <first>Mark</first>
    <last>Smith</last>
    </person>
    </xml>

    I want to get partial xml data, for example I want to get just the second person data, and I want to get based on the attribute, in this case the ID. Is there a way how to do that? Thanks in advance, Laziale

    P 0 N A 4 Replies Last reply
    0
    • L laziale

      hello once again today - I do have one more question and I hope that someone can help me one more time today again. I have an xml document similar to this one:

      <person id="1">
      <first>John</first>
      <last>Smith</last>
      </person>
      <person id="2">
      <first>Mark</first>
      <last>Smith</last>
      </person>
      </xml>

      I want to get partial xml data, for example I want to get just the second person data, and I want to get based on the attribute, in this case the ID. Is there a way how to do that? Thanks in advance, Laziale

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      You'll have to write some code.

      N 1 Reply Last reply
      0
      • L laziale

        hello once again today - I do have one more question and I hope that someone can help me one more time today again. I have an xml document similar to this one:

        <person id="1">
        <first>John</first>
        <last>Smith</last>
        </person>
        <person id="2">
        <first>Mark</first>
        <last>Smith</last>
        </person>
        </xml>

        I want to get partial xml data, for example I want to get just the second person data, and I want to get based on the attribute, in this case the ID. Is there a way how to do that? Thanks in advance, Laziale

        0 Offline
        0 Offline
        0x3c0
        wrote on last edited by
        #3

        Yes; look into XPath queries. The correct query would be something along the lines of "//xml/person[id='2']". You simply have to plug that into and example like this; there are other examples you could use as well

        Between the idea And the reality Between the motion And the act Falls the Shadow

        1 Reply Last reply
        0
        • L laziale

          hello once again today - I do have one more question and I hope that someone can help me one more time today again. I have an xml document similar to this one:

          <person id="1">
          <first>John</first>
          <last>Smith</last>
          </person>
          <person id="2">
          <first>Mark</first>
          <last>Smith</last>
          </person>
          </xml>

          I want to get partial xml data, for example I want to get just the second person data, and I want to get based on the attribute, in this case the ID. Is there a way how to do that? Thanks in advance, Laziale

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          You can use an XPath expression to retrieve the xml fragment, ./person[@id='2'] will return the second person element in this case


          only two letters away from being an asset

          L 1 Reply Last reply
          0
          • P PIEBALDconsult

            You'll have to write some code.

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            How insightful


            only two letters away from being an asset

            1 Reply Last reply
            0
            • N Not Active

              You can use an XPath expression to retrieve the xml fragment, ./person[@id='2'] will return the second person element in this case


              only two letters away from being an asset

              L Offline
              L Offline
              laziale
              wrote on last edited by
              #6

              ok, sorry everyone cause I didn't provide any code, but here is what I tried:

                string innerXml = "";
              

              innerXml = docCompany.Attributes[selectedItem].OuterXml;

              and it give me an error NullReferenceObject any other way?

              N 1 Reply Last reply
              0
              • L laziale

                ok, sorry everyone cause I didn't provide any code, but here is what I tried:

                  string innerXml = "";
                

                innerXml = docCompany.Attributes[selectedItem].OuterXml;

                and it give me an error NullReferenceObject any other way?

                N Offline
                N Offline
                Not Active
                wrote on last edited by
                #7

                As we have been telling you, use an xpath query http://msdn.microsoft.com/en-us/library/hcebdtae.aspx[^]


                only two letters away from being an asset

                1 Reply Last reply
                0
                • L laziale

                  hello once again today - I do have one more question and I hope that someone can help me one more time today again. I have an xml document similar to this one:

                  <person id="1">
                  <first>John</first>
                  <last>Smith</last>
                  </person>
                  <person id="2">
                  <first>Mark</first>
                  <last>Smith</last>
                  </person>
                  </xml>

                  I want to get partial xml data, for example I want to get just the second person data, and I want to get based on the attribute, in this case the ID. Is there a way how to do that? Thanks in advance, Laziale

                  A Offline
                  A Offline
                  Adam R Harris
                  wrote on last edited by
                  #8

                  You should look into LINQ for this, I absolutely LOVE LINQ when working with XML files. http://www.codeproject.com/KB/linq/LinQ\_To\_Xml.aspx That's a good article that shows pretty much exactly how to do what you need. Sorry for the crappy link, all the fancy JavaScript that formats it doesn't work on my iPhone (stupid safari)

                  If at first you don't succeed ... post it on The Code Project and Pray.

                  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