Skip to content

Change a xmlTree

Marco

Asked Jan 20, 2008, 12:37 PM EST1 answer
Share
LinkedInX
Hello, I created my own xmlTree with this last instruction:
   Xml_doc.AppendChild(xml_root);
it is in this way: <html> <script> </script> <body> </body> </html>
Now I need to modify it: for example I need to add <head> </head> in this way:
<html> <head>  <script> </script> </head> <body> </body> </html>
How can I do this? Do I have to re-build the tree???
thanks.
I tried in this way, but It insert only <head/> after <html>. Why? isn't it strange?
EDIT: ------------------------------------------
            XmlElement head = Xml_doc.CreateElement("head");          
            XmlNode body = xml_root.FirstChild;
            xml_root.RemoveAll();
            xml_root.AppendChild(head);
            xml_root.AppendChild(body);
            Xml_doc.AppendChild(xml_root);

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    hello, I solved it, but now one strange problem is arise:
    With this code below, inside output.html I see '<' and '>' insetead of < and >
    How can I solve? Thanks.

    XmlTextWriter xmlW = new XmlTextWriter("..\\..\\output.html", null);
               xmlW.Formatting = Formatting.Indented;         
               pdom.Xml_doc.WriteContentTo(xmlW);
               xmlW.Close();
    EDIT --
    the problem is that, in xml_doc, I have attached to one tag   (as innerTEXT) a string (which contains some tags...!!!! and those tags get me the < problem in output file)....
    0