Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[3227] XML Node Insert

Last post 09-18-2007 3:00 PM by adhakshi. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [3227] XML Node Insert

    This thread is for discussions of XML Node Insert.

    • Post Points: 25
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 10-25-2005 7:04 AM In reply to

    Create Documet Fragments

    Hi,

    thanks for this solution. i am working on html whether this solution is compatible with html (IHTMLDocument3) ?

    regards
    Digitaldigs
    "There is no good documentation than code itself"
    • Post Points: 0
  • 04-27-2007 7:38 AM In reply to

    • gsrk_in
    • Not Ranked
    • Joined on 04-27-2007
    • India
    • New Member
    • Points 20

    Re: [3227] XML Node Insert

        Hi,

    This is what exactly i was looking for .. thanks for the solution.. its really short and sweet.

    regards





    • Post Points: 5
  • 07-24-2007 7:15 AM In reply to

    Re: [3227] XML Node Insert

    Its a good post above

    VK

    http://www.dotnetuncle.com

     

    • Post Points: 5
  • 07-24-2007 10:25 AM In reply to

    Re: [3227] XML Node Insert

    Yes.  Inserting a node is fine.

    But how about inserting a node at a particular place in the XML Tree.

    Say an an XML Tree of a School, with Subjects, where each Subject has Classes, and Each Class has Students.   Say deleting all students from the Anthropology Class  <Class Name="athropology"> and moving another set of students there.

    I find that i need to use a combination of .net classes (XPathNodeIterator & XPathNavigator  )

    I then create the iterator from the current position in the navigator.

    I use the iterator to ask about this current position in navigator.

    If it is the "right" position i use: XPatheNavigator.InnerXml

    Or XPathNavigator.AppendChild(XmlNode);

    You method of build child nodes from a start node can be used here.

    You need need the XPathNavigator to find your way around. You use the XPathNodeIterator to ask questions about where you are in the Navigator. 

    You can for example can use XPathNavigator.ReadSubTree.  Edit it.  Then delete one level beneath , where you currently are in the Navigator (via the Interator), & then use the edite subtree to insert.

    Does anybody have good for the above.  I can supply what i have done.  But i think there might be other ways to do it too.

     

     

    • Post Points: 10
  • 09-18-2007 3:00 PM In reply to

    • adhakshi
    • Not Ranked
    • Joined on 09-18-2007
    • India
    • New Member
    • Points 10

    Re: [3227] XML Node Insert

    First, navigate to the right place using MoveToChild method and use PrependChild method to append your new node. Here is the sample code:

               string itemXML = "<student .... />";

                XmlDocument objDocument = new XmlDocument();
                objDocument.Load(xmlFileName);

                XPathNavigator objNavigator = objDocument.CreateNavigator();
                objNavigator.MoveToChild("School", "");
                objNavigator.MoveToChild("Subjects", "");
                objNavigator.MoveToChild("Classes", "");
                objNavigator.MoveToChild("Students", "");

                objNavigator.PrependChild(itemXml);

                Console.WriteLine(objNavigator.OuterXml);

    • Post Points: 5
Page 1 of 1 (6 items)