You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Nikolay Georgiev <ng...@gistec-online.de> on 2006/01/23 16:24:16 UTC

[Digester] Parse an Element containing random data

Hello,

can I make the Digester to parse an XML element that contains random
data(characters, say HTML code) from it's beginning to it's end and then
save the data in a string.

For example:

<section>
	<text>
		I want to save this text with these tags <b>as a String Object</b>. <br />
	</text>
</section>

Is it possible?

Regards,
Nikolay


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


AW: [Digester] Parse an Element containing random data

Posted by Nikolay Georgiev <ng...@gistec-online.de>.
Thanks,

wrapping it in a CDATA section works great :)

Regards,
Nikolay

-----Ursprüngliche Nachricht-----
Von: Simon Kitching [mailto:skitching@apache.org]
Gesendet: Montag, 23. Januar 2006 23:56
An: Jakarta Commons Users List
Betreff: Re: [Digester] Parse an Element containing random data


On Mon, 2006-01-23 at 16:24 +0100, Nikolay Georgiev wrote:
> Hello,
>
> can I make the Digester to parse an XML element that contains random
> data(characters, say HTML code) from it's beginning to it's end and then
> save the data in a string.
>
> For example:
>
> <section>
> 	<text>
> 		I want to save this text with these tags <b>as a String Object</b>. <br
/>
> 	</text>
> </section>
>
> Is it possible?

Digester takes its input from an XML parser, and there is no way to tell
an XML parser to "stop treating the input as xml for a while" - except
by wrapping the input in CDATA.

If your input was:
 <text>
<![CDATA[
  ....<b>...</b>...<br/>
]]>
 </text>

then everything would work as you want. This is the correct way to
represent arbitrary text embedded within an xml document.

If the content is valid XML, then you could use NodeCreateRule to turn
the content of the <text> element into a dom tree, then walk that tree
to turn it back into text.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Digester] Parse an Element containing random data

Posted by Simon Kitching <sk...@apache.org>.
On Mon, 2006-01-23 at 16:24 +0100, Nikolay Georgiev wrote:
> Hello,
> 
> can I make the Digester to parse an XML element that contains random
> data(characters, say HTML code) from it's beginning to it's end and then
> save the data in a string.
> 
> For example:
> 
> <section>
> 	<text>
> 		I want to save this text with these tags <b>as a String Object</b>. <br />
> 	</text>
> </section>
> 
> Is it possible?

Digester takes its input from an XML parser, and there is no way to tell
an XML parser to "stop treating the input as xml for a while" - except
by wrapping the input in CDATA.

If your input was:
 <text>
<![CDATA[
  ....<b>...</b>...<br/>
]]>
 </text>

then everything would work as you want. This is the correct way to
represent arbitrary text embedded within an xml document.

If the content is valid XML, then you could use NodeCreateRule to turn
the content of the <text> element into a dom tree, then walk that tree
to turn it back into text.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org