gpt4 book ai didi

java - SAX异常 : Content is not allowed in trailing section

转载 作者:数据小太阳 更新时间:2023-10-29 01:59:41 26 4
gpt4 key购买 nike

这让我发疯。我已经将这段代码用于许多不同的项目,但这是它第一次给我这种类型的错误。这是整个 XML 文件:

  <layers>
<layer name="Layer 1" h="400" w="272" z="0" y="98" x="268"/>
<layer name="Layer 0" h="355" w="600" z="0" y="287" x="631"/>
</layers>

这是我自制的 Xml 类中的可操作代码,它使用 DocumentBuilderFactory 来解析输入其中的 Xml:

public static Xml parse(String xmlString)
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document doc = null;
//System.out.print(xmlString);
try
{
doc = dbf.newDocumentBuilder().parse(
new InputSource(new StringReader(xmlString)));
// Get root element...
Node rootNode = (Element) doc.getDocumentElement();
return getXmlFromNode(rootNode);
} catch (ParserConfigurationException e)
{
System.out.println("ParserConfigurationException in Xml.parse");
e.printStackTrace();
} catch (SAXException e)
{
System.out.println("SAXException in Xml.parse ");
e.printStackTrace();
} catch (IOException e)
{
System.out.println("IOException in Xml.parse");
e.printStackTrace();
}
return null;
}

我使用它的背景是:制作 Photoshop 类型图像处理应用程序的学校项目。该文件与图层一起保存为 .png,此 xml 文件用于 .zip 文件中图层的位置等。我不知道压缩是否添加了一些神秘的额外字符。

感谢您的反馈。

最佳答案

如果您在编辑器中查看该文件,您会在结束元素之后看到内容(可能是空格),例如

</layers>  <-- after here

值得使用一个可以突出显示空白字符的工具来解决这个问题,例如

$ cat -v -e my.xml

将转储“不可打印”字符。

关于java - SAX异常 : Content is not allowed in trailing section,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13682727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com