简体   繁体   English

在GAEJ应用中解析C#客户端生成的xml时,尾部异常中出现不良内容

[英]Getting bad content in trailing section exception, when parsing xml produced by C# client in a GAEJ app

I am trying to POST a potentially large chunk of xml from a C# client to a GAEJ app, and then parse it into a DOM document. 我正在尝试从C#客户端向GAEJ应用发布可能很大的xml块,然后将其解析为DOM文档。

I've managed to get the documentbuilder to parse the xml by parsing the request data into a string and then trimming it, as such: 我已经设法通过将请求数据解析为字符串,然后对其进行修整,来使documentbuilder解析xml,如下所示:

        String xml;
        BufferedReader rdr = req.getReader();
        String line;
        StringBuilder result = new StringBuilder();
        while ((line = rdr.readLine()) != null) {
            result.append(line);
        }
        xml = result.toString();
        db = dbf.newDocumentBuilder();
        Document doc = db.parse(new InputSource(new StringReader(xml.trim())));

However the GAEJ app should be as efficient as possible and reading the potentially large xml input to a string line by line, as opposed to feeding the sourcestream to the parser, seems quite bad. 但是,GAEJ应用程序应尽可能高效,并且将可能较大的xml输入逐行读取到字符串中,而不是将sourcestream馈送到解析器,这似乎很糟糕。 I would like the following to work: 我希望以下工作:

        Document doc = db.parse(request.getInputStream());

But then I always get "org.xml.sax.SAXParseException: Content is not allowed in trailing section." 但是然后,我总是收到“ org.xml.sax.SAXParseException:尾部不允许出现内容”。 If I dump the contents of the request.getInputStream() call to the console I can see some box-characters after the final closing tag, but I'm not sure how they got there (the clientside is using UTF-8 encoding), or how to remove them from the input stream. 如果我将request.getInputStream()调用的内容转储到控制台,我可以在最后的结束标记后看到一些方框字符,但是我不确定它们如何到达那里(客户端使用的是UTF-8编码),或如何从输入流中删除它们。 Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM