Adding xml to an ‘Any’ Element

Sometimes you will need to add an XML fragment into another XML document. A good example of this would be while constructing a SOAP request.

A simple solution to this would be to just build a string value and use the ToXml() method to add the xml fragment from your object model.

E.g. This C# example shows inserting an XML message part into a OpenTravel webservice SOAP request:

string soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?><SOAP-ENV:Envelope xmlns:xsi=\"\" xmlns:xsd=\"\" xmlns:SOAP-ENV=\"\"><SOAP-ENV:Body><tns:OTA_VehLocSearch xmlns:tns=\"\" xmlns=\"\" xmlns:xsi=\"\">";

soap = soap + liquidObj.ToXml();

soap = soap + "</tns:OTA_VehLocSearch></SOAP-ENV:Body></SOAP-ENV:Envelope>";


However, sometimes you will have the entire structure in your Liquid XML generated Object Model, where the above XML message part is represented as an ‘Any’ element within the XSD. In the scenario, you will need to use the ‘Element’ object within your code.

E.g.  This C# example shows inserting an XML message part as a generic Element object:

Envelope env = new Envelope ();

Element elm = new Element();