Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

After parsing [Node].getLocalName() returns null ??

843834Oct 7 2003 — edited Oct 8 2003
Hello

I'm parsing a valid XML File, which is a soap message. So I parse the file, have some elements, but when I want to create a SOAPElement and initialize it with theNode.getLocalName(), theNode.getNamespaceURI(), and so on, I find out the node has no values set .... and I do not know why :-(

I'd appreciate any advice. Thanx in advance.


For your convenience some code snippets regarding my problem:
/* Setting up the parser, parsing the specified file, calling the formatter.

public void setUp() throws Exception
    {
        try
        {
            soapMessage = MessageFactory.newInstance().createMessage();
            setSOAPElements();
        }
        catch (SOAPException e3)
        {
            // TODO Auto-generated catch block
            e3.printStackTrace();
        }
        //    Print contents of XML file
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        dbFactory.setIgnoringElementContentWhitespace(true);
        DocumentBuilder builder = null;
        
        try
        {
            builder = dbFactory.newDocumentBuilder();
            builder.isNamespaceAware();
        }
        catch (ParserConfigurationException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Document doc = null;
        try
        {
            doc = builder.parse(new File("messages/ts_msg.xml"));
        }
        catch (SAXException e1)
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        catch (IOException e1)
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try
        {
            SOAPElement xmlMessage =
                convertDOMToSOAPElement(soapEnvelope,  doc.getFirstChild());                   
            soapEnvelope.addChildElement(xmlMessage);
        }
        catch (SOAPException e)
        {
        	e.printStackTrace();
        }        
    }

[/code}

And here is the method where the error appears first:
public SOAPElement convertDOMToSOAPElement(
SOAPEnvelope envelope,
org.w3c.dom.Node domNode)
throws SOAPException
{
if ((domNode.getNodeType()) != org.w3c.dom.Node.ELEMENT_NODE)
{
throw new SOAPException("Node must be of type ELEMENT_NODE");
}
else
{
System.out.println("Fuckking hell");
SOAPFactory sef = SOAPFactory.newInstance();
SOAPElement se =
sef.createElement(
domNode.getLocalName(),
domNode.getPrefix(),
domNode.getNamespaceURI());

if (domNode.hasAttributes())
{
NamedNodeMap DOMAttributes = domNode.getAttributes();
int noOfAttributes = DOMAttributes.getLength();
for (int i = 0; i < noOfAttributes; i++)
{
org.w3c.dom.Node attr = DOMAttributes.item(i);
se.addAttribute(
envelope.createName(
attr.getLocalName(),
attr.getPrefix(),
attr.getNamespaceURI()),
attr.getNodeValue());
}
}
if (domNode.hasChildNodes())
{
NodeList children = domNode.getChildNodes();
for (int i = 0; i < children.getLength(); i++)
{
org.w3c.dom.Node child = children.item(i);
System.out.println("Switching types");
switch (child.getNodeType())
{
case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE :
break;
case org.w3c.dom.Node.DOCUMENT_TYPE_NODE :
break;
case org.w3c.dom.Node.TEXT_NODE :
{
se.addTextNode(child.getNodeValue());
break;
}
default :
se.addChildElement(
convertDOMToSOAPElement(envelope, child));
}
} //end of for
} //end of if
return se;
}
}



Thankx for any help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 5 2003
Added on Oct 7 2003
1 comment
627 views