Resolving which version of an XML Schema to use for XML documents with a version attribute

前端 未结 2 1946
忘了有多久
忘了有多久 2021-01-25 11:45

I have to write some code to handle reading and validating XML documents that use a version attribute in their root element to declare a version number, like this:



        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-25 12:32

    My Suggestion

    1. Parse the Document using SAX or DOM
    2. Get the version attribute
    3. Use the Validator.validate(Source) method and and use the already parsed Document (from step 1) as shown below

    Building DOMSource from parsed document

    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(new File(args[0]));
    
    domSource = new DOMSource(document);
    

提交回复
热议问题