Skip to main content

Namespace error processing standard geopriv location xml

No replies
kaydat
Offline
Joined: 2010-02-22
Points: 0

I'm using Java 6 and trying to send a SOAP message with the following XML
<?xml version="1.0" encoding="UTF-8"?>

US
New York
New York
Broadway
123
Suite 75
10027-0401

yes
2003-06-23T04:57:29Z

2003-06-22T20:57:29Z

The code is below.
public class doc {
public static void main(String[] args)
{
try {
// Create a DocumentBuilderFactory and a DocumentBuilder
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
// Instead of parsing an XML document, however, just create an empty
// document that you can build up yourself.
System.out.println("Filename specified: " + args[0]);
Document document = db.parse(new File(args[0]));
System.out.println("Done parsing xml");

MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
//Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
//envelope.addNamespaceDeclaration("", "http://ww.cisco.com/geolocation/notification");

System.out.println("Adding doc to body");
body.addDocument(document);
//Save the message
System.out.println("Saving the message");
message.saveChanges();

System.out.println("\nREQUEST:\n");
message.writeTo(System.out);
System.out.println();
}
catch(Exception e) {
e.printStackTrace();
}

//Check the input
}
-----
When processing, I see the error

org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.setName(ElementNSImpl.java:149)
at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.(ElementNSImpl.java:80)
at com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl.(ElementImpl.java:97)
at com.sun.xml.internal.messaging.saaj.soap.impl.ElementFactory.createElement(ElementFactory.java:78)
at com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl.createElement(SOAPDocumentImpl.java:99)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1528)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1731)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1731)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1731)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1731)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1487)
at com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl.importNode(SOAPDocumentImpl.java:146)
at com.sun.xml.internal.messaging.saaj.soap.impl.BodyImpl.addDocument(BodyImpl.java:232)
at doc.main(doc.java:43)

I have no clue why this standard XML would fail. Appreciate any pointes