String to XML java parse

时间:2014-02-03 10:06:12

标签: java xml-parsing

我的字符串包含如下字符:č,ć,š,ž等。

这是将字符串转换为xml的代码:

public Document convertStringToDocument() throws SAXException, ParserConfigurationException, IOException {
        String xmlStr = new String(getString());
        try  
        {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();  
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(new InputSource(new StringReader(out)));


            return doc;
        } catch (Exception e) {  
            e.printStackTrace();  
        } 
        return null;
    }

我得到了这个错误:

[致命错误]:6:30:元素类型“Punu_x0020_i_x0020_skra”必须跟随属性规范,“>”或“/>”。 org.xml.sax.SAXParseException; lineNumber:6; columnNumber:30;元素类型“Punu_x0020_i_x0020_skraÔ必须后跟属性规范“>”或“/>”。     at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)     at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)     在com.reports.service.ReportsWS.convertStringToDocument(ReportsWS.java:49)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     at java.lang.reflect.Method.invoke(Unknown Source)     在org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)     在org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)     在org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)     在org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)     在org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)     在org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)     在org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)     在org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)     在org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:647)     在org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:728)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)     在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)     在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)     在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)     在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)     在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)     在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)     at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:607)     在org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:313)     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)     在java.lang.Thread.run(未知来源)

0 个答案:

没有答案