aspose file tools*
The moose likes XML and Related Technologies and the fly likes Create XML Document from String? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Create XML Document from String?" Watch "Create XML Document from String?" New topic
Author

Create XML Document from String?

richard marais
Ranch Hand

Joined: Aug 20, 2001
Posts: 30
I have a String that consists of XML data & tags. I need to convert the String to a JDOM Document Object. Does anyone know how?
I have tried the following with no success:
public void setXMLResultSetString(String pResSetString)
{
try
{
System.out.println(pResSetString);
SAXBuilder db = new SAXBuilder();
StringReader sr = new StringReader (pResSetString);
Document doc = db.build((Reader)sr);
System.out.println(doc);
...
I get the following error:
[Document: No DOCTYPE declaration. Root - [Element: <ResultSet/>]]
The pResSetString is the following:
<?xml version="1.0" encoding="UTF-8"?>
<ResultSet Name="Timesheet Project" TotalRows="16">
<!--Timesheet Project-->
<Row num="1">
<description>Document System -</description>
<project_name>Document System</project_name>
<client_id>1001</client_id>
<client_name>Merill Lynch</client_name>
</Row>
<Row num="2">
<description>Chase System -</description>
<project_name>Chase System</project_name>
<client_id>1002</client_id>
<client_name>Chase</client_name>
</Row>
<Row num="3">
<description>Chase System - Development</description>
<project_name>Chase System</project_name>
<client_id>1002</client_id>
<client_name>Chase</client_name>
</Row>
<Row num="4">
<description>Somelia COOL:Gen -</description>
<project_name>Somelia COOL:GEN</project_name>
<client_id>1003</client_id>
<client_name>Someila</client_name>
</Row>
<Row num="5">
<description>Customer Meeting/Presentation</description>
<project_name>Customer</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="6">
<description>Preparation for Meetings, etc.</description>
<project_name>Customer</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="7">
<description>Research & Development</description>
<project_name>R&D</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="8">
<description>Inhouse Self Study</description>
<project_name>Inhouse</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="9">
<description>External Training</description>
<project_name>Inhouse</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="10">
<description>Inhouse Courses</description>
<project_name>Inhouse</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="11">
<description>Orygen Internal Meeting</description>
<project_name>null</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="12">
<description>Account Specific Meetings</description>
<project_name>null</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="13">
<description>Account Management</description>
<project_name>null</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="14">
<description>Annual Leave</description>
<project_name>null</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="15">
<description>Sick Leave</description>
<project_name>null</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
<Row num="16">
<description>Bank Holidays</description>
<project_name>null</project_name>
<client_id>1004</client_id>
<client_name>Orygen</client_name>
</Row>
</ResultSet>
Paramagurusamy Balasubramanian
Ranch Hand

Joined: Aug 17, 2001
Posts: 55
Hi,
Since '&' is one of the predefined entities in xml,U can't those symbols in xml.So remove the '&' symbol at row num=7 from the xml file and replace by 'and';
Hope this would work..
Best Regards,
Paramaguru.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Create XML Document from String?