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. Repeat XML node

Repeat XML node

Scheduled Pinned Locked Moved C#
csharpxml
10 Posts 3 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.
  • K Offline
    K Offline
    kurangu
    wrote on last edited by
    #1

    I am having an XMl like below <Details> <det id=1 name="abc"> </Details> Now i want to take the above xml as input and to repeat the node like below using C# <Details> <det id=1 name="abc"/> <det id=2 name="abc"/> <det id=3 name="abc"/> </Details>

    L 1 Reply Last reply
    0
    • K kurangu

      I am having an XMl like below <Details> <det id=1 name="abc"> </Details> Now i want to take the above xml as input and to repeat the node like below using C# <Details> <det id=1 name="abc"/> <det id=2 name="abc"/> <det id=3 name="abc"/> </Details>

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      :confused:

      K 1 Reply Last reply
      0
      • L Lost User

        :confused:

        K Offline
        K Offline
        kurangu
        wrote on last edited by
        #3

        Rich, Just I want to repeat the node in aloop by incrementing id.

        L 1 Reply Last reply
        0
        • K kurangu

          Rich, Just I want to repeat the node in aloop by incrementing id.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I don't understand what your problem is. What code are you using to create the original XML, and what code have you tried to create the repeat items?

          K 1 Reply Last reply
          0
          • L Lost User

            I don't understand what your problem is. What code are you using to create the original XML, and what code have you tried to create the repeat items?

            K Offline
            K Offline
            kurangu
            wrote on last edited by
            #5

            Rich, In c#.Original xml is a string which I get like below <details> <detail id="1" name="x"/> </details> I want to take that xml string and to repeat the nodes foreach xml nodes <details> <detail id="1" name="x"/> <detail id="2" name="x"/> <detail id="3" name="x/> </details> id=2 and id=3 is repeated.want to do it in C#

            M L 2 Replies Last reply
            0
            • K kurangu

              Rich, In c#.Original xml is a string which I get like below <details> <detail id="1" name="x"/> </details> I want to take that xml string and to repeat the nodes foreach xml nodes <details> <detail id="1" name="x"/> <detail id="2" name="x"/> <detail id="3" name="x/> </details> id=2 and id=3 is repeated.want to do it in C#

              M Offline
              M Offline
              Mirko1980
              wrote on last edited by
              #6

              That can be easly done using XmlDocument. You know that class? Have you already tried something or you want us to give all the code to you (that you won't get here, I'm afraid)?

              1 Reply Last reply
              0
              • K kurangu

                Rich, In c#.Original xml is a string which I get like below <details> <detail id="1" name="x"/> </details> I want to take that xml string and to repeat the nodes foreach xml nodes <details> <detail id="1" name="x"/> <detail id="2" name="x"/> <detail id="3" name="x/> </details> id=2 and id=3 is repeated.want to do it in C#

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                kurangu wrote:

                In c#.Original xml is a string which I get like below

                Where do you get this from, a const string, XmlReader, TextReader?

                kurangu wrote:

                I want to take that xml string and to repeat the nodes

                I ask again, what code have you tried; please help us to understand better what you are actually doing in your code?

                K 1 Reply Last reply
                0
                • L Lost User

                  kurangu wrote:

                  In c#.Original xml is a string which I get like below

                  Where do you get this from, a const string, XmlReader, TextReader?

                  kurangu wrote:

                  I want to take that xml string and to repeat the nodes

                  I ask again, what code have you tried; please help us to understand better what you are actually doing in your code?

                  K Offline
                  K Offline
                  kurangu
                  wrote on last edited by
                  #8

                  HI, It's a constant string. string a = "<SecDetails><Security PrimarySecID=\"abcd\" Price=\"12\"/></SecDetails>"; XmlDocument originalXml = new XmlDocument(); originalXml.LoadXml(a); XmlNodeList nodelist = originalXml.SelectNodes("/SecDetails/Security"); foreach (XmlNode xn in nodelist) { here I should be able to repeat the node for (int i=1; i<=10;i++) { I am struck here. } }

                  M L 2 Replies Last reply
                  0
                  • K kurangu

                    HI, It's a constant string. string a = "<SecDetails><Security PrimarySecID=\"abcd\" Price=\"12\"/></SecDetails>"; XmlDocument originalXml = new XmlDocument(); originalXml.LoadXml(a); XmlNodeList nodelist = originalXml.SelectNodes("/SecDetails/Security"); foreach (XmlNode xn in nodelist) { here I should be able to repeat the node for (int i=1; i<=10;i++) { I am struck here. } }

                    M Offline
                    M Offline
                    Mirko1980
                    wrote on last edited by
                    #9

                    Look at the XmlNode class, in particular, the ParentNode property and the AppendChild and CloneNode methods. You should have now all the element you need to perform your task.

                    1 Reply Last reply
                    0
                    • K kurangu

                      HI, It's a constant string. string a = "<SecDetails><Security PrimarySecID=\"abcd\" Price=\"12\"/></SecDetails>"; XmlDocument originalXml = new XmlDocument(); originalXml.LoadXml(a); XmlNodeList nodelist = originalXml.SelectNodes("/SecDetails/Security"); foreach (XmlNode xn in nodelist) { here I should be able to repeat the node for (int i=1; i<=10;i++) { I am struck here. } }

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Now I'm even more confused, I don't see a relation between what you have posted here, and the XML statements from your original post. If you are saying that you don't know how to format a string in C# then I suggest you look at the documentation for the String class. If you are unsure of the Xml data formats then look at the items referred to by Mirko1980. If you are having trouble understanding the for or foreach statements then take a look at the C# documentation.

                      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