5
votes

This is what I'm trying to parse,

<?xmlversion="1.0"encoding="UTF-8"standalone="no"?>
<newPlayerConnectionrequest>
    <‌​participantType>1</participantType>
</newPlayerConnectionrequest>

Client code creating the message:

Element rootElement = document.createElement(MyServer.NEW_PLAYER_CONNECTION_REQUEST);
    Element participantTypeElement = document.createElement(MyServer.PARTICIPANT_TYPE);
    Text textParticipantType = document.createTextNode(participantType);
    participantTypeElement.appendChild(textParticipantType);
    rootElement.appendChild(participantTypeElement);
    document.appendChild(rootElement);
    StringWriter sw = new StringWriter();
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer;
    try {
        transformer = tFactory.newTransformer();
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(sw);
        transformer.transform(source, result);
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    }
    catch (TransformerException t) {
        t.printStackTrace();
    }
    try {
        conn.setRequestMethod("POST");
    } catch (ProtocolException e) {
        e.printStackTrace();
    }
    conn.setRequestProperty("Content-Type", "text/xml");
    //conn.setRequestProperty("Content-Length", "" +  8);
    conn.setRequestProperty("Content-Language", "en-US");  
    conn.setDoInput(true);
    conn.setDoOutput(true

and I am getting the following error:

White space is required between the processing instruction target and data.
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 13;
    White space is required between the processing instruction target and data.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:253)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:288)
at MyServer.doPost(MyServer.java:91)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:643)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:450)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:229)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1067)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:377)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1001)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
at org.eclipse.jetty.server.Server.handle(Server.java:360)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454)

Edit The string I am trying to parse:

1
The string I am trying to parse: <?xmlversion="1.0"encoding="UTF-8"standalone="no"?><newPlayerConnectionrequest><participantType>1</participantType></newPlayerConnectionrequest>Trup

1 Answers

12
votes

This line is wrong

<?xmlversion="1.0"encoding="UTF-8"standalone="no"?>

It should read

<?xml version="1.0"encoding="UTF-8"standalone="no"?>

Note the space between "xml" and "version"

Google is your friend ;)