Is it possible to get an XDocument from an XmlNode?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Iaml

    Is it possible to get an XDocument from an XmlNode?

    I searched a little, and saw a few people who also wanna do this, but
    I haven't found a solution.

    Thank you.
  • Marc Gravell

    #2
    Re: Is it possible to get an XDocument from an XmlNode?

    Untested, but how about:

    XmlNode node;// TODO
    XDocument doc = XDocument.Load( new XmlNodeReader(n ode));

    Comment

    • ArunDhaJ

      #3
      Re: Is it possible to get an XDocument from an XmlNode?

      you can use OwnerDocument attribute of XMLNode class...

      -ArunDhaJ

      Comment

      • Iaml

        #4
        Re: Is it possible to get an XDocument from an XmlNode?

        On Jun 4, 3:39 pm, ArunDhaJ <arund...@gmail .comwrote:
        you can use OwnerDocument attribute of XMLNode class...
        >
        -ArunDhaJ
        Thank you, but I think OwnerDocument property returns an XmlDocument
        instead of XDocument. I explicitly want XDocument, not XmlDocument.

        Comment

        • Iaml

          #5
          Re: Is it possible to get an XDocument from an XmlNode?

          On Jun 4, 3:33 pm, Marc Gravell <marc.grav...@g mail.comwrote:
          Untested, but how about:
          >
          XmlNode node;// TODO
          XDocument doc = XDocument.Load( new XmlNodeReader(n ode));
          That may work since XmlNodeReader is an XmlReader and the XDocument's
          Load method does take an XmlReader argument. I need to give it a
          shot. Thank you.

          Comment

          • Iaml

            #6
            Re: Is it possible to get an XDocument from an XmlNode?

            On Jun 4, 3:33 pm, Marc Gravell <marc.grav...@g mail.comwrote:
            Untested, but how about:
            >
            XmlNode node;// TODO
            XDocument doc = XDocument.Load( new XmlNodeReader(n ode));
            Just tested it, it works like a charm. Thanks a lot.

            Comment

            Working...