• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Problem reading XML

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I have problem reading the XML basically the CDATA.I have a XML File,for the SQL queries in key value pair.The format is shown as below

<database-queries>
<query name = "some query">
select * from sometable where something <= 1;
</query>
</database-queries>
Now when I use the above xml Iam getting error for "<=" and I got to use the CDATA.My java code that reads the XML is as below.Iam reading teh XML file and storing them in hashmap as key/value pair.But using CDATA ,Iam getting SQL Exception..Is there any way of loading the queries and using the CDATA as well.

NodeList list = document.getChildNodes();
Node node = list.item(0);
if(node.getNodeName().equals("database-queries"))
{
NodeList nodes = node.getChildNodes();
for(int j = 0; j < nodes.getLength(); j++)
{
Node cnode = nodes.item(j);
if(cnode.getNodeName().equals("query"))
{
NamedNodeMap attrList = cnode.getAttributes();
String queryName = attrList.getNamedItem("name").getNodeValue();
String query = cnode.getFirstChild().getNodeValue();
dbMap.put(queryName, query);

Thanks in advance
Shiv
 
Sheriff
Posts: 28347
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So your first problem was that the code that produced the XML didn't escape text nodes properly. You solved that by using a CDATA section. So far so good.

Now the data in the XML document causes an SQLException. Well, this might be because it's invalid SQL, or because you don't have a connection, or anything. It probably is nothing to do with XML. However without knowing about the exception, it's difficult to say anything useful.

The first thing you should post is the description of the exception, and also the actual query you are trying to execute. Don't extract it from the XML assuming you know what the code is doing, do System.out.println in that code to see what query it is really trying to execute.
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic