You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by John Woolsey <jw...@activation.net> on 2004/08/24 14:38:16 UTC
JAXP Problems
Okay I am having trouble with JAXP. I parse through the tree and find my
element_nodes easily. Then I go for getNodeValue and it always seems to
be null. I am using Xerces 2 to process. Any ideas what I am doing wrong?
- thanx - JAW
System.setProperty(
"javax.xml.parsers.DocumentBuilderFactory",
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
return dfactory = DocumentBuilderFactory.newInstance();
HashMap result = new HashMap();
Document doc = XML.getFactory().newDocumentBuilder().parse(
new InputSource( new FileInputStream(deployPath +
"META-INF/ejb-jar.xml")));
Node node = XPathAPI.selectSingleNode( doc,
"ejb-jar/enterprise-beans");
NodeList childList = node.getChildNodes();
for( int i=0;i<childList.getLength();i++){
Node child = childList.item(i);
if( child.getNodeType() == Node.ELEMENT_NODE){
Element element = (Element)child;
String name = element.getTagName();
NamedNodeMap namedNodeMap = element.getAttributes();
System.out.println( name + " " +
namedNodeMap.item(0).getNodeValue() );
result.put( name, child.getNodeValue() );
}
}
return result;
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<!-- Session Beans -->
<session>
<description>Mail Processing Session Bean.</description>
<display-name>MailProcessingServerDisplayName</display-name>
<ejb-name>MailProcessingServer</ejb-name> <!-- Matches with
JBoss.xml -->
<home>honour.session.MailProcessHome</home>
<remote>honour.session.MailProcess</remote>
<ejb-class>honour.session.MailProcessBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
Re: [ot] JAXP Problems
Posted by John Woolsey <jw...@activation.net>.
After much futzing around I realized that the data is a child node and
then things got better. Thanx for the help.
- bfn - JAW
toby cabot wrote:
>On Tue, Aug 24, 2004 at 08:38:16AM -0400, John Woolsey wrote:
>
>
>>Okay I am having trouble with JAXP. I parse through the tree and find my
>>element_nodes easily. Then I go for getNodeValue and it always seems to
>>be null. I am using Xerces 2 to process. Any ideas what I am doing wrong?
>>
>>
>>
>snip...
>
>
>> Node child = childList.item(i);
>> if( child.getNodeType() == Node.ELEMENT_NODE){
>> Element element = (Element)child;
>> String name = element.getTagName();
>> NamedNodeMap namedNodeMap = element.getAttributes();
>> System.out.println( name + " " +
>>namedNodeMap.item(0).getNodeValue() );
>> result.put( name, child.getNodeValue() );
>>
>>
>
>I'm not a JAXP expert, but I play one on mailing lists. I checked the
>javadoc of the Node class and it looks as if it's behaving as
>documented: the nodeValue of an element node is null.
>
>http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Node.html
>
>see the table in the introduction.
>
>HTH,
>Toby
>
>
>
>
Re: [ot] JAXP Problems
Posted by toby cabot <to...@caboteria.org>.
On Tue, Aug 24, 2004 at 08:38:16AM -0400, John Woolsey wrote:
> Okay I am having trouble with JAXP. I parse through the tree and find my
> element_nodes easily. Then I go for getNodeValue and it always seems to
> be null. I am using Xerces 2 to process. Any ideas what I am doing wrong?
>
snip...
> Node child = childList.item(i);
> if( child.getNodeType() == Node.ELEMENT_NODE){
> Element element = (Element)child;
> String name = element.getTagName();
> NamedNodeMap namedNodeMap = element.getAttributes();
> System.out.println( name + " " +
> namedNodeMap.item(0).getNodeValue() );
> result.put( name, child.getNodeValue() );
I'm not a JAXP expert, but I play one on mailing lists. I checked the
javadoc of the Node class and it looks as if it's behaving as
documented: the nodeValue of an element node is null.
http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Node.html
see the table in the introduction.
HTH,
Toby
Re: [ot] JAXP Problems
Posted by Dain Sundstrom <da...@coredevelopers.net>.
John,
In the future when you want to start a new thread on the mailing list,
please create a new message in your email client instead of replying to
an existing message and clearing out the subject and body. On most
email clients this "thread hijacking" messes up messaged threading.
Thanks,
-dain
On Aug 24, 2004, at 5:38 AM, John Woolsey wrote:
> Okay I am having trouble with JAXP. I parse through the tree and find
> my element_nodes easily. Then I go for getNodeValue and it always
> seems to be null. I am using Xerces 2 to process. Any ideas what I am
> doing wrong?
>
>
> - thanx - JAW
>
> System.setProperty(
> "javax.xml.parsers.DocumentBuilderFactory",
> "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
> return dfactory = DocumentBuilderFactory.newInstance();
> HashMap result = new HashMap();
>
> Document doc = XML.getFactory().newDocumentBuilder().parse(
> new InputSource( new FileInputStream(deployPath +
> "META-INF/ejb-jar.xml")));
> Node node = XPathAPI.selectSingleNode( doc,
> "ejb-jar/enterprise-beans");
>
> NodeList childList = node.getChildNodes();
> for( int i=0;i<childList.getLength();i++){
> Node child = childList.item(i);
> if( child.getNodeType() == Node.ELEMENT_NODE){
> Element element = (Element)child;
> String name = element.getTagName();
> NamedNodeMap namedNodeMap = element.getAttributes();
> System.out.println( name + " " +
> namedNodeMap.item(0).getNodeValue() );
> result.put( name, child.getNodeValue() );
> }
> }
> return result;
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
> JavaBeans 2.0//EN"
> "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
> <ejb-jar>
> <enterprise-beans>
> <!-- Session Beans -->
> <session>
> <description>Mail Processing Session Bean.</description>
> <display-name>MailProcessingServerDisplayName</display-name>
> <ejb-name>MailProcessingServer</ejb-name> <!-- Matches with
> JBoss.xml -->
> <home>honour.session.MailProcessHome</home>
> <remote>honour.session.MailProcess</remote>
> <ejb-class>honour.session.MailProcessBean</ejb-class>
> <session-type>Stateless</session-type>
> <transaction-type>Container</transaction-type>
> </session>
> </enterprise-beans>
> </ejb-jar>