Is there a way to specify that part of an XML file should be treated as a string even though it looks like XML?
September 22, 2004 10:24 AM   Subscribe

Is there a way to specify that part of an XML file should be treated as a string even though it looks like XML? [more inside]

Example:
<Data>
<1></1>
</Data>

I'd like the validator or reader to read "<1></1>" as a string rather than two tags.

Do I just have to use lt; and gt;?
posted by callmejay to Computers & Internet (7 answers total)
 
You can use a CDATA section to tell the parser to treat data as characters, not XML.
posted by normy at 10:39 AM on September 22, 2004


(while we're at it, is there another way to do it on MeFil as well?)
posted by callmejay at 10:43 AM on September 22, 2004


bingo, normy. Thanks.
posted by callmejay at 10:45 AM on September 22, 2004


Yes, if you're just trying to represent < - the character - then use the character entity &lt;. The problem with CDATA is that it's a blob that can't contain markup, so consider CDATA a last resort.
posted by holloway at 2:26 PM on September 22, 2004


Actually though, <1></1> looks like markup to me -- why are you trying to treat it as a string?
posted by holloway at 2:42 PM on September 22, 2004


Well, I need a slot in an XML file which can contain arbitrary strings, some of which may happen to be XML but aren't logically a part of that file's XML structure.

Wholly fabricated example:

<Object>
<Name>Foo</Name>
<Date></Date>
<OtherData>
Has a cat
</OtherData>
<OtherData>
I have some strings with XML like <Key>53</Key>
</OtherData>
</Object>
posted by callmejay at 4:49 PM on September 22, 2004


I think that other valid xml outside the main datastructure is usually done with a different namespace, like,

<main:OtherData>
    I have some strings with XML like <Key>53</Key>
</main:OtherData>

Not that it really matters to the software :)
posted by holloway at 9:56 PM on September 22, 2004


« Older Big Beetles   |   Why does humming make me have to pee? Newer »
This thread is closed to new comments.