XElement xdoc = new XElement(node.Name,node.InnerXml);
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Marked as answer by guywithdoubts on Aug 27, 2008 02:00 PM
My root element of XML source has few attributes associated with it.
If I write the following, it gives me what I need:
Dim xe As XElement = XElement.Load(New XmlNodeReader(GetTaskBarXML(FormName)))
But, if I write in the following manner, it gives different XElement and thus I am unable to use:
Dim xn As XmlNode = GetTaskBarXML(FormName)
Dim xe As
New XElement(xn.Name, xn.InnerXml) ---not even xn.OuterXml is giving out properly
After examining a bit in depth, I came to see that in the first case, xe.Value is empty. Where as, in the second case, xe.Value contains what I am getting from InnerXml/OuterXml. But xe is automatically HTML encoded in the second case. How to solve this
problem. I am interested in the second case (as you suggested), if it works as expected in the first case.
guywithdoubt...
Member
2 Points
7 Posts
How to convert XMLNode to XElement (without any parsing)?
Aug 22, 2008 09:40 PM|LINK
I have an object as following:
Dim
oDef As Xml.XmlNode = GetFromRemoteSource();dim oXE as XElement = ?????
How do I creat XElement from an existing XmlNode? I don't want to convert XmlNode to string and again parse the same to get to XElement.
Any solution available?
Thanks in Advance.
Bonekrusher
Contributor
4027 Points
922 Posts
Re: How to convert XMLNode to XElement (without any parsing)?
Aug 24, 2008 08:06 PM|LINK
XSLT is perfect for what you want to do.
guywithdoubt...
Member
2 Points
7 Posts
Re: How to convert XMLNode to XElement (without any parsing)?
Aug 25, 2008 02:51 PM|LINK
XElement is a LINQ class. I am not going to transform anything to use XSLT. I would like to query few things using LINQ to XML.
Any more ideas?
thanks
Samu Zhang -...
All-Star
62163 Points
6101 Posts
Re: How to convert XMLNode to XElement (without any parsing)?
Aug 26, 2008 10:32 AM|LINK
Hi guywithdoubts ,
XElement xdoc = new XElement(node.Name,node.InnerXml);
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
guywithdoubt...
Member
2 Points
7 Posts
Re: How to convert XMLNode to XElement (without any parsing)?
Aug 27, 2008 02:00 PM|LINK
thanks. It worked!
However, I got a small issue.
My root element of XML source has few attributes associated with it.
If I write the following, it gives me what I need:
Dim xe As XElement = XElement.Load(New XmlNodeReader(GetTaskBarXML(FormName)))
But, if I write in the following manner, it gives different XElement and thus I am unable to use:
Dim xn As XmlNode = GetTaskBarXML(FormName) Dim xe As New XElement(xn.Name, xn.InnerXml) ---not even xn.OuterXml is giving out properlyAfter examining a bit in depth, I came to see that in the first case, xe.Value is empty. Where as, in the second case, xe.Value contains what I am getting from InnerXml/OuterXml. But xe is automatically HTML encoded in the second case. How to solve this problem. I am interested in the second case (as you suggested), if it works as expected in the first case.
Can you help me out on this as well?
thanks