Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] How do you get CDATA types within a text element?

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: lenards AT email.arizona.edu
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] How do you get CDATA types within a text element?
  • Date: Wed, 6 Aug 2008 14:50:04 -0700

Hello XOM-interest,

I need to deliver documents that have CDATA types like the following:

<agent role="photographer">
<![CDATA[<i>James Pataki</i>]]>
</agent>

I see in the JavaDoc for the Text class the mention that "CDATA sections are
not
treated differently than normal text". And I noticed that there is a CDATA
type
defined in child class Attribute.Type.

My code looks like this:

Element agentEl = new Element("agent", NS);
agentEl.addAttribute(new Attribute("homepage", homepage));
agentEl.addAttribute(new Attribute("role",
AgentRole.Author.toString()));
agentEl.appendChild(new Text("<i>" + key + "</i>"));

Now, I understand that I get escaping of characters for free (or at least
that's
the behavior I'm seeing).

<agent homepage="http://www.six-fifty.com/";
role="Author">
&lt;i&gt;James Pataki&lt;/i&gt;</agent>

But I've been asked to put CDATA sections around the inner-text (even though
I've been told that's not really the correct approach anymore, escaping is).

I would expect that there might be a way to control or override the Text
class's
behavior. Or extend it. Or maybe I can't. I know that XOM is lightweight,
and
well-designed, so maybe this use case isn't supported because it's a bad
approach.

Anyway, I can't find an example nor figure out how to get a CDATA section
emitted inside an element. Is this even possible with XOM? Can I reproduce
the first example listed?

Thanks in advance!

Andy









Archive powered by MHonArc 2.6.24.

Top of Page