Is it possible to get an XDocument from an XmlNode?

  • Thread starter Thread starter Iaml
  • Start date Start date
I

Iaml

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

Thank you.
 
Untested, but how about:

XmlNode node;// TODO
XDocument doc = XDocument.Load(new XmlNodeReader(node));
 
you can use OwnerDocument attribute of XMLNode class...

-ArunDhaJ
 
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.
 
Untested, but how about:

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

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.
 
Untested, but how about:

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

Just tested it, it works like a charm. Thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top