0
votes

following:

I write live stream data into an XML file and want to parse it later with StaX. Because the live stream data occure sometimes realy frequent, the write stream process "swallows up" sometimes what ends in (partially) malformed XML files.

Now I get parsing errors at some point in the file.

Is there a way to tell the StaX parser to skip malformed pasages in the XML file? Is it possible to push the cursor forward until the malformed part is done? For sure, I will work on the writing algorithm as well, but I need a robust parsing mechanism too.

Currently I parsing with an XMLStreamReader.

Thanks Jonathan

1
by streaming, are you referring to a continuous, never-ending large XML, or a long procession of xml documents? - vtd-xml-author

1 Answers

0
votes

How about using validation using stax but it will be one pass only as Stax does not support other way.

public class StaxValidationCheckDemo {

    public static void main (String args[]) throws Exception {

        XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream("myxml.xml"));

        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new File("myxml.xsd"));

        Validator validator = schema.newValidator();
        validator.validate(new StAXSource(reader));

        //its valid if there are no error or no exception thrown else invalid

    }
}