• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Create XML Document from String?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic