tags:

views:

40

answers:

1

I have an xml document that has a structure like so:

 <?xml version="1.0" encoding="iso-8859-1" ?> 
- <newdataset xml="version="1.0" encoding="iso-8859-1"">
- <officelist>
  <officeid>2</officeid> 
  <office>Office</office> 
  <region>BC</region> 

I would like to have the office id = 2 to be its own element. Like so

 <?xml version="1.0" encoding="iso-8859-1" ?> 
<newdataset xml="version="1.0" encoding="iso-8859-1"">
    <officelist>
      <officeid id=2/>
          <office>Office</office> 
          <region>BC</region> 
     </officeid>
   </officelist>
</newdataset>

xmlDS += offices.GetXml();

xmlDS = xmlDS.Replace(@"xml:space=""preserve""", " ");               
XmlDocument doc = new XmlDocument();
XmlNode declaration = doc.CreateNode(XmlNodeType.XmlDeclaration, null, null);

doc.LoadXml(xmlDS);
doc.Save(Response.OutputStream);

That is my code so far... not sure how to set a child node to become a parent node

A: 

using XDocument made this a lot easier with Linq.

Spooks