You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Robert Koberg <ro...@koberg.com> on 2001/07/26 18:14:25 UTC

help - java - Basic DOM parse

I must be missing something very basic about DOM parsing.

Here is an excerpt of the java code:

DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docbuilder = dfactory.newDocumentBuilder();
Document doc = docbuilder.parse(this_config);

context.setAttribute("boo1", this_config);
context.setAttribute("boo2", doc);

The output indicates the correct file (with or without the file:///) if I
check it in the filesystem, but doc is always null.  dfactory, docbuilder
all show that they have been created. The xml file is well-formed.

thanks for any help,
Rob


---------------------------------------------------------------------
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


xalan d7 build bug? was - Re: help - java - Basic DOM parse

Posted by Robert Koberg <ro...@koberg.com>.
I failed to mention I am using Xalan (D7).  In the documentation (that says
D6 at the top) it states:
---------------------
The Java API for XML Processing interfaces enable you to isolate your
application from the internal implementation details of a given Transformer,
SAX parser, or DOM parser. For each of these objects, there is an abstract
Factory class with a static newInstance() method that instantiates a
concrete Factory which wraps the underlying implementation. These
newInstance() methods use system property settings to determine which
implementation to instantiate.
Xalan-Java is distributed with system property settings for the Xalan XSLT
Transformer and the Xerces DOM and SAX parsers. These settings are in
xalan.jar in META-INF/services (see src/META-INF/services).
System property Setting
javax.xml.transform.TransformerFactory
org.apache.xalan.processor.TransformerFactoryImpl
javax.xml.parsers.DocumentBuilderFactory
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
javax.xml.parsers.SAXParserFactory
org.apache.xerces.jaxp.SAXParserFactoryImpl
-------------------------------

But when I look in the xalan.jar there is only:
javax.xml.transform.TransformerFactory
org.apache.xalan.processor.TransformerFactoryImpl



----- Original Message -----
From: "Robert Koberg" <ro...@koberg.com>
To: <ge...@xml.apache.org>
Sent: Thursday, July 26, 2001 9:14 AM
Subject: help - java - Basic DOM parse


> I must be missing something very basic about DOM parsing.
>
> Here is an excerpt of the java code:
>
> DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
> DocumentBuilder docbuilder = dfactory.newDocumentBuilder();
> Document doc = docbuilder.parse(this_config);
>
> context.setAttribute("boo1", this_config);
> context.setAttribute("boo2", doc);
>
> The output indicates the correct file (with or without the file:///) if I
> check it in the filesystem, but doc is always null.  dfactory, docbuilder
> all show that they have been created. The xml file is well-formed.
>
> thanks for any help,
> Rob
>
>
> ---------------------------------------------------------------------
> 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
>


---------------------------------------------------------------------
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: help - java - Basic DOM parse

Posted by Robert Koberg <ro...@koberg.com>.
thanks for responding, I will try to be clearer:

> Sorry, I don't understand the question.  What is "this_config"

it is an uri or an InputStream (or others, I have tried several)
 Document doc = docbuilder.parse(this_config);
 -- but it an XML document that describes the particular site in it's
context

> "context" in the code above

sorry. context is:
// in the servlet's init (actually a startup servlet)
ServletContext context  = getServletConfig().getServletContext();

> and what is the problem you are trying to
> solve?

I want to be able to put the parsed doc in a context attribute to access it
in other parts of this (or a master) webapp:

 context.setAttribute("boo2", doc);

I know I have the doc in the class that sets the attribute because I can
perform XPath expressions on it using the XPathAPI.  But I can't put doc
into the attribute - it always turns up null.  I am pretty sure I won't end
up doing this, but I just wanted to see if the performance is acceptable for
the convenience the DOM offers.





----- Original Message -----
From: "Edwin Goei" <ed...@sun.com>
To: <ge...@xml.apache.org>
Sent: Thursday, July 26, 2001 11:03 AM
Subject: Re: help - java - Basic DOM parse


> Robert Koberg wrote:
> >
> > I must be missing something very basic about DOM parsing.
> >
> > Here is an excerpt of the java code:
> >
> > DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
> > DocumentBuilder docbuilder = dfactory.newDocumentBuilder();
> > Document doc = docbuilder.parse(this_config);
> >
> > context.setAttribute("boo1", this_config);
> > context.setAttribute("boo2", doc);
> >
> > The output indicates the correct file (with or without the file:///) if
I
> > check it in the filesystem, but doc is always null.  dfactory,
docbuilder
> > all show that they have been created. The xml file is well-formed.
>
> Sorry, I don't understand the question.  What is "this_config" and
> "context" in the code above and what is the problem you are trying to
> solve?
>
> -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
>


---------------------------------------------------------------------
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: help - java - Basic DOM parse

Posted by Edwin Goei <ed...@sun.com>.
Robert Koberg wrote:
> 
> I must be missing something very basic about DOM parsing.
> 
> Here is an excerpt of the java code:
> 
> DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
> DocumentBuilder docbuilder = dfactory.newDocumentBuilder();
> Document doc = docbuilder.parse(this_config);
> 
> context.setAttribute("boo1", this_config);
> context.setAttribute("boo2", doc);
> 
> The output indicates the correct file (with or without the file:///) if I
> check it in the filesystem, but doc is always null.  dfactory, docbuilder
> all show that they have been created. The xml file is well-formed.

Sorry, I don't understand the question.  What is "this_config" and
"context" in the code above and what is the problem you are trying to
solve?

-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