File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Unable to parse an xml string using builder.parse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Unable to parse an xml string using builder.parse " Watch "Unable to parse an xml string using builder.parse " New topic
Author

Unable to parse an xml string using builder.parse

Praveen Shivashankar
Greenhorn

Joined: Jul 20, 2008
Posts: 13
Hi,

I am trying to take an xml string, convert that into a document type to be used for a function that is expected to verify the validity of the contents of this xml string. However, after converting to a document type, the builder.parse() attribute doesn't seem to return any values at all, due to which the validation function is failing. Given below is a code snippet for this.

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

String xmlResponse = "<?xml version="1.0" encoding="UTF-8" standalone="no"?><AuthRes code="5ee2f1d4-4cd6-4996-abad-9a2bc64847a9" info="01a8e6dc0e0c7eb69fb2897d2065284f578bcdfd6e18000000" ret="y" txn="DefaultTXN"><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>K2NuXDP3eFgzglLeHCD6tpogEvs=</DigestValue></Reference></SignedInfo><SignatureValue>m8XsACzxcFPxHRGqkD8tBzKTLlo9azB2e+4+RJ2c4sVettq6QymcVN1BIx0PYfu/lUDxxNlGHsWjcODcrdWnSlYff/6k8sBaTTAkq8+RTATokAOP9LRMgbszfCJLQx1Or+p8EUaeI5J+jEHe+pGFh6b/lsttX6p69lWeq6bp8oI=</SignatureValue></Signature></AuthRes>"

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document resDocument = builder.parse(new InputSource(new StringReader(responseBody)));

if(verify(resDocument)){
System.out.println("The Signature is certified properly");
}


I like talking to myself, coz I always hear what I like!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
Surely that is not the real code building that String, with all those quote characters mixed in.

Why are you so sure a Document is being created? Where are the statements to catch ard report exceptions?

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to parse an xml string using builder.parse