开发者

Changing an XML Child Element into a Parent

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);

T开发者_如何学Pythonhat is my code so far... not sure how to set a child node to become a parent node


using XDocument made this a lot easier with Linq.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜