You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Kate Lapan <ka...@Peakstone.com> on 2001/04/14 03:04:00 UTC

JAXP/Crimson Document question

I'm trying to create a document from an xml string.  I modified the example
code that comes with crimson, but for some reason, the document is null even
though the input source is fine.  Below is my code.

-----------------------------------------------------------------------

// Step 1: create a DocumentBuilderFactory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// Step 2: create a DocumentBuilder
DocumentBuilder db = dbf.newDocumentBuilder();
// Step 3: parse the input file to get a Document object
InputSource input = new InputSource(new StringReader(requestText));
Document requestDom = db.parse(input);

-----------------------------------------------------------------------

Does anyone know how to make the above work properly?

If this is not the correct alias for this question, can you please point me
in the right direction?

Thanks in advance,

Kate

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Re: JAXP/Crimson Document question

Posted by Edwin Goei <ed...@sun.com>.

Kate Lapan wrote:
> 
> I'm trying to create a document from an xml string.  I modified the example
> code that comes with crimson, but for some reason, the document is null even
> though the input source is fine.  Below is my code.
> 
> -----------------------------------------------------------------------
> 
> // Step 1: create a DocumentBuilderFactory
> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> // Step 2: create a DocumentBuilder
> DocumentBuilder db = dbf.newDocumentBuilder();
> // Step 3: parse the input file to get a Document object
> InputSource input = new InputSource(new StringReader(requestText));
> Document requestDom = db.parse(input);
> 
> -----------------------------------------------------------------------
> 
> Does anyone know how to make the above work properly?

The above code should work.  Of course, you need to wrap the code in a
try/catch block.  So you are saying that "requestDom" is null?  This
should not happen.  Unfortunately, I don't have any ideas.  What version
of Crimson are you using?  You could try your app with Xerces.

BTW, newer apps will want to turn on namespace processing, so you need
to add dbf.setNamespaceAware(true) before creating a new
DocumentBuilder.

-Edwin

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org