Title: RE: [jdjlist] XML Parsing of an xml message string

OK, here goes ...


    /**
     * Converts the XML String to XML Document.
     * GOTCHA: all the " -> \";
     * @note ADDED: normalize routine -- will remove all empty text nodes,
     * so <root>    <el1> is not a problem. <GN>
     *
     * @author Greg Nudelman <GN>
     * @param stringXML to convert to Document.
     * @exception CustomException if can not parse the XML string
     */
    public static Document stringToDocument(String stringXML) throws CustomException {
        Document dom = null;

        try {

            byte[] byteXML = stringXML.getBytes();
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteXML);
            InputStream inputStream;
            inputStream = (InputStream)byteArrayInputStream;

            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            dom = docBuilder.parse(inputStream);


        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("Malformed XML. Exception: " + e);
        }
        //XmlHelper.normalizeDocument(dom); //you may want to normalize
        //the document to remove all the blank text elements
        return dom;
    }


-----Original Message-----
From: Anurag Sikchi [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 18, 2002 5:05 AM
To: JDJList
Subject: [jdjlist] XML Parsing of an xml message string



I need to parse an xml string received as a string message. I am using the xerces parser. Could somebody tell me how do to this.

The parser.parse() method in the api expects a file uri. However, I need to pase an xml string and not a file.

thanks,
Anurag

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to