Tag: xmlstreamreader

StAX XML两个必需标记之间的所有内容

开始学习StAX,使用XMLStreamReader,我遇到了一些问题。 如何将标签之间的所有内容作为文本? 我的意思是,我知道所需标签的名称,当我找到它时,我必须转到关闭标签,我发现它们之间的一切我必须附加一些字符串。 例如,我们有类似的东西 … Some text content and other tags here… Some text content.. … Something here … … … 所以,我需要把我的字符串作为 Some text content.. … Something here 我怎么才能得到它? 也许,我必须在源xml中找到所需块的开始和结束偏移,并在解析后给出子串?

如何使用失败的xsdvalidation获取xml文件的元素和无效的xml文件

我目前正在使用我的XSD来validation我的xml。 这部分工作正常我的问题是我想获得无效的标签/值的元素。 InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); XMLStreamReader reader = null; SchemaFactory factory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(xsdschemalocation); Validator validator = schema.newValidator(); try { reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(new StringReader(xml))); } catch (XMLStreamException ex) { LogController.getLogger().logSEVERE(“Unable to create the streamreader from the xml source”, ex.getLocalizedMessage()); return false; } try { validator.validate(new StAXSource(reader)); } catch (IOException […]