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.