Search code examples
xmlscalacdata

SCALA Extract CData content from XML


I have the following xml:

`<a><b><![CDATA[<c><d>mycontent</d></c>]]</b></a>`

and I want to extract the XML structure under CDATA and find the value of <d> tag under CDATA . How can I do that in Scala ??


Solution

  • There is no XML structure and no <d> tag under the CDATA. CDATA means "character data", it means "there might be stuff in here that looks like XML markup, but don't be misled, it's just plain text". So if you want to treat it as XML with structure, don't put it in CDATA.

    Or, if you're stuck with the data in the form it is supplied, extract the content of the CDATA section as text, and submit it to an XML parser to identify the structure.