view raw
NullPointer NullPointer - 1 year ago 51 Question

Create XMLElement from partial XML

first off apologies I have never coded with XML constructs in .NET so I hope the question makes sense.

Let me start by defining my XML:







I get this entire XML as a String.

I need to now call another function which takes a custom class as an argument. The custom class has 2 properties: 1 is another custom class which contains the routing information and the other is of type System.Xml.XmlElement. The signature is something like this:

public class Message
Public header as HeaderInfo
Public payload as System.Xml.XmlElement
End Class

In essence, I need to convert everything within the
tags to a type System.Xml.XmlElement, maintaining the XML structure under PayLoad (I was able to generate the HeaderInfo class)

The XML schema is fixed and it will always have the same elements in it.

Any ideas on how to do this?
I'm using VB.NET on .NET 3.5



You can use XmlDocument to get the <Payload> element as XmlElement without reparsing, for example :

Dim doc As New XmlDocument()
doc.LoadXml("Your XML string goes here")
Dim payload As XmlElement = DirectCast(doc.SelectSingleNode("//Payload"), XmlElement)