Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 256
none Avatar asked Jan 25 '12 18:01

none


People also ask

Can we store data in XML?

XML documents you insert into columns of type XML can reside either in the default storage object, or directly in the base table row. Base table row storage is under your control and is available only for small documents; larger documents are always stored in the default storage object.

What is &GT in XML?

The ampersand character (&) starts entity markup (the first character of a character entity reference). &gt; The greater-than character (>) ends a start-tag or an end-tag.

What is Cdata in XML example?

The term CDATA means, Character Data. CDATA is defined as blocks of text that are not parsed by the parser, but are otherwise recognized as markup. The predefined entities such as &lt;, &gt;, and &amp; require typing and are generally difficult to read in the markup. In such cases, CDATA section can be used.

How do you specify XML version and encoding in an XML document?

To avoid errors, you should specify the encoding used, or save your XML files as UTF-8. UTF-8 is the default character encoding for XML documents. Character encoding can be studied in our Character Set Tutorial. UTF-8 is also the default encoding for HTML5, CSS, JavaScript, PHP, and SQL.


1 Answers

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;
like image 83
Mike Christensen Avatar answered Sep 19 '22 18:09

Mike Christensen