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. Database & SysAdmin
  3. Database
  4. Table result to Xml

Table result to Xml

Scheduled Pinned Locked Moved Database
data-structuresxmltutorialquestion
2 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.
  • F Offline
    F Offline
    Fayu
    wrote on last edited by
    #1

    Hi, I am trying to convert a table result to a xml. For example, I have a result (Figure 1) and I want to make an xml out of it (Figure 2). I have tried the FOR XML RAW and FOR XML AUTO but this does not seem to give me the tree structure. Any ideas? Figure 1:

    Parent Id Name

    0 1 Root
    0 2 Root 2
    1 3 Child 1
    1 4 Child 2
    3 5 Child 3
    4 6 Child 4
    9 7 Child 5

    Figure 2:

    <NodeCollection>
    <Node rId=1 Parent=0 Name='Root'>
    <Node rId=3 Parent=1 Name='Child 1'>
    <Node rId=5 Parent=3 Name='Child 3' />
    </Node>
    <Node rId=4 Parent=1 Name='Child 2'>
    <Node rId=6 Parent=4 Name='Child 4' />
    </Node>
    </Node>
    <Node rId=2 Parent=0 Name='Root 2' />
    <Node rId=7 Parent=9 Name='Child 5' />
    </NodeCollection>

    R 1 Reply Last reply
    0
    • F Fayu

      Hi, I am trying to convert a table result to a xml. For example, I have a result (Figure 1) and I want to make an xml out of it (Figure 2). I have tried the FOR XML RAW and FOR XML AUTO but this does not seem to give me the tree structure. Any ideas? Figure 1:

      Parent Id Name

      0 1 Root
      0 2 Root 2
      1 3 Child 1
      1 4 Child 2
      3 5 Child 3
      4 6 Child 4
      9 7 Child 5

      Figure 2:

      <NodeCollection>
      <Node rId=1 Parent=0 Name='Root'>
      <Node rId=3 Parent=1 Name='Child 1'>
      <Node rId=5 Parent=3 Name='Child 3' />
      </Node>
      <Node rId=4 Parent=1 Name='Child 2'>
      <Node rId=6 Parent=4 Name='Child 4' />
      </Node>
      </Node>
      <Node rId=2 Parent=0 Name='Root 2' />
      <Node rId=7 Parent=9 Name='Child 5' />
      </NodeCollection>

      R Offline
      R Offline
      Riaan Booyzen
      wrote on last edited by
      #2

      Hi Fayu, Have a look at trying for xml explicit, try this article for some help http://www.eggheadcafe.com/articles/20030804.asp[^] Hope you get it working

      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