[jdom-interest] Problems Retrieving data from CDATA
Richard Cook
rpc at prismtechnologies.com
Tue May 8 11:45:29 PDT 2001
Eg:
import org.jdom.*;
import org.jdom.input.*;
import java.io.*;
public class CData
{
private final String testData = "<?xml version = '1.0'?> <rootTag>
<tag1>Kyle</tag1> <tag2>kyle</tag2> <tag3>Kyle</tag3> <tag4>\n" +
"<![CDATA[\n" +
"<?xml version='1.0'?>\n" +
"<exampleCDATA>\n" +
"<Kyle>test</Kyle>\n" +
"<Gregg>Test</Gregg>\n" +
"<John>Test</John>\n" +
"</exampleCDATA>\n" +
"]]>\n" +
"</tag4> </rootTag>";
public static void main(String [] args)
{
try {
new CData().run();
}
catch (Exception e) {
System.err.println("Except: " + e);
}
}
public void run() throws Exception
{
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new StringReader(testData));
Element root = doc.getRootElement();
String text = root.getChild("tag4").getText();
System.out.println(text);
text = text.trim();
Document newDoc = builder.build(new StringReader(text));
java.util.Iterator iter =
newDoc.getRootElement().getChildren().iterator();
while (iter.hasNext()) {
System.out.println(iter.next());
}
}
}
-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]On
Behalf Of kyle miller
Sent: Tuesday, May 08, 2001 6:51 PM
To: 'jdom-interest at jdom.org'
Subject: [jdom-interest] Problems Retrieving data from CDATA
I am having problems getting the data out of a CDATA section of an xml
document, and I was wondering if anyone has done this or if their are any
suggestions as how to accomplish this...Kyle
Here is the example doc:
<?xml version = "1.0"?>
<rootTag>
<tag1>Kyle</tag1>
<tag2>kyle</tag2>
<tag3>Kyle</tag3>
<tag4>
<![CDATA[
<?xml version="1.0"?>
<exampleCDATA>
<Kyle>test</Kyle>
<Gregg>Test</Gregg>
<John>Test</John>
</exampleCDATA>
]]>
</tag4>
</rootTag>
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
More information about the jdom-interest
mailing list