Tag: xml 1.1

如何使用Java和Xerces解析确认1.1规范的XML?

我正在尝试解析包含符合XML 1.1规范的 XML内容的String。 XML包含XML 1.0规范中不允许但在XML 1.1规范中允许的字符引用(字符引用转换为U + 0001-U + 001F范围内的Unicode字符)。 根据Xerces2网站, Xerces2解析器支持解析XML 1.1文档。 但是,我无法弄清楚如何告诉它我们试图解析的XML包含1.1兼容的XML。 我正在使用DocumentBuilder来解析XML(类似这样): public Element parseString(String xmlString) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = dbf.newDocumentBuilder(); InputSource source = new InputSource(new StringReader(xmlString)); // Throws org.xml.sax.SAXParseException becuase of the invalid character refs Document doc = documentBuilder.parse(source); return doc.getDocumentElement(); } catch (ParserConfigurationException pce) […]