Jump to content

Validar XML em Android


Tsubas
 Share

Recommended Posts

Boas Tardes!!!

Bem ando aqui de volta da maneira de validar o xml que o meu programa recebe através de um schema que lhe envio para validar.

Encontrei já um exemplo que para java normal corre, mas que em android me dá erro em:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder loader = factory.newDocumentBuilder();
Document document = loader.parse("XML.xml");

// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory schemaFact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(new File("Modelo XML.xsd"));
Schema schema = schemaFact.newSchema(schemaFile);

// create a Validator instance, which can be used to validate an instance document
Validator validator = schema.newValidator();

// validate the DOM tree
try {
   validator.validate(new DOMSource(document));
   System.out.println("CERTO");
} catch (SAXException e) {
   // instance document is invalid!
   System.out.println(e);
}

SchemaFactory schemaFact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Nesta linha em android recebo o erro de:

01-15 18:08:31.833: E/action(6915): java.lang.IllegalArgumentException: http://www.w3.org/2001/XMLSchema-instance

Já procurei na net, mas ainda não encontrei uma solução, se alguém puder ajudar, agradecia  👍

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.