Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to parse an xml string using builder.parse  RSS feed

Praveen Shivashankar
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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=""><SignedInfo><CanonicalizationMethod Algorithm=""/><SignatureMethod Algorithm=""/><Reference URI=""><Transforms><Transform Algorithm=""/></Transforms><DigestMethod Algorithm=""/><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)));

System.out.println("The Signature is certified properly");

William Brogden
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!