Extract a <node> as a new XMLDocument?

C

Carlos Albert

Hello,

Would you tell me if there is a way to extract a single node as a new
xmldocument?

Thanks.
 
G

Guest

Carlos,
You would need to :
1) Create a new XmlDocument.
2) use the ImportNode method to bring in the node from the other XmlDocument.

See MSDN Library Help or online for code samples.

Peter
 
C

Carlos Albert

Tnx, but I tried to do this and I'm doing something very wrong (cause it
doesn't work at all):

Dim big_xml As New XmlDocument

big_xml.LoadXml(xml)

Dim small_xml As New XmlDocument

Dim result As XmlNode =
small_xml.ImportNode(big_xml.GetElementsByTagName("node_tag_name").Item(0),
True)

small_xml.DocumentElement.AppendChild(result)
 
G

Guest

Break up your code into smaller pieces so it's easier to see what is happening
on each line with debugger step-through.
Also, ensure the new document has the correct processing instruction, root
element, etc. to be valid.
Also, it looks to me like you are trying to import your node from the new
document instead of the original!

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 
C

Carlos Albert

Made it work, thanks! =)

Dim big_xml As New XmlDocument
big_xml.LoadXml(xml)
Dim small_xml As New XmlDocument
Dim result As XmlNode
result =
small_xml.ImportNode(big_xml.GetElementsByTagName("small_xml").Item(0),
True)
small_xml.LoadXml("<small_xml>" & result.InnerXml & "</small_xml>")
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top