none
none

Reputation: 4847

store xml inside xml

Using OmniXML package, is it possible to store XML code inside another XML file that has its own XML data?

Like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<data>
   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <otherxml>data</otherxml>
</data>

where inside the tag data, everything should be data. Is there an escape char that prevent the parser from parsing the next data into the XML data structure?

Or Does OmniXML comes with support for serialization for this situation?

Any other simple ideas are also welcome.

Upvotes: 11

Views: 6527

Answers (2)

Mike Christensen
Mike Christensen

Reputation: 91716

You can use CDATA:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<data>
   <![CDATA[
   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <otherxml>data</otherxml>
   ]]>
</data>

Note when you get the value for data, it will be as a string so you'd have to run it through a new XML parser.

Here is an example code for omniXML:

var
  xml:IXMLDocument;
  Node:IXMLNode;
begin
  xml := CreateXMLDoc;    
  xml.SelectSingleNode('/root/data',Node);
  ShowMessage(GetNodeCData(Node,'data',''));
end;

Upvotes: 23

Daniel Luyo
Daniel Luyo

Reputation: 1336

if the content in data doesn't have to be read rigth away you can encode it in for example Base64 or UUEncode.

Then you can extract, decode and parse the data

Upvotes: 3

Related Questions