After search on internet and in differnets forums, have not found my answer.
I have a XML file which is define by two XSD schema.
For write the XML file, there are two ways to write the XML file :
(I have to delete the "<" charactere to display the XML file)
First methode to write it :\[code\]?xml version="1.0" encoding="UTF-8" standalone="yes"?>Policy xmlns="http://www.W3C.com/Policy/v3#" xmlns:ns2="http://www.W3C.com /PolicyExtension/v3#">DigestAlg Algorithm="http://test"/>Transforms>Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n20010315"></Transform>/Transforms> ns2:Validation> ns2:ConditionID>1.0.1</ns2:ConditionID> ns2:TConditionID>1.0.2</ns2:TConditionID> /ns2:Validation>/Policy>" \[/code\]second methodes :\[code\]?xml version="1.0" encoding="UTF-8" standalone="yes"?>Policy xmlns="http://www.W3C.com/Policy/v3#">DigestAlg Algorithm="http://test"/>Transforms>Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n20010315"></Transform>/Transforms> Validation xmlns:ns2="http://www.W3C.com/PolicyExtension/v3#"> ConditionID>1.0.1</ns2:ConditionID> TConditionID>1.0.2</ns2:TConditionID> /Validation>/Policy> \[/code\]For pasring my XML files, i use :\[code\]InputStream doc = new FileInputStream(myXMLFile);DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); List<Source> sourceListSchema = new ArrayList<Source>(); sourceListSchema.add(new StreamSource(SignaturePolicy.class.getResourceAsStream(MY_XSD_SCHEMA_1))); sourceListSchema.add(new StreamSource(SignaturePolicy.class.getResourceAsStream(MY_XSD_SCHEMA_2))); Schema schema; try { Source[] sourceTmp = new Source[1]; schema = sf.newSchema(sourceListSchema.toArray(sourceTmp)); } catch (SAXException e) { LogMachine.logger.severe( "SAXException : The schema can not be parse :"+e.getMessage()); } dbf.setIgnoringElementContentWhitespace(true); dbf.setNamespaceAware(true); dbf.setIgnoringComments(true); dbf.setSchema(schema); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); documentPolicy = db.parse(Doc); } catch (ParserConfigurationException e) { LogMachine.logger.severe( "ParserConfigurationException : the file can not be parse by DOM :"+e.getMessage()); } catch (SAXException e) { LogMachine.logger.severe( "SAXException : the file can not be parse by DOM :"+e.getMessage()); } catch (IOException e) { LogMachine.logger.severe( "IOException : the file can not be open like a file :"+e.getMessage()); }\[/code\]When I want to parse this documents with DOM, the first XML file display an error
Exception in thread "main" org.w3c.dom.ls.LSException: The prefix "ns2" for element "ns2:Validation" is not bound.But the second XML file is well parse.Someone can help me to parse the two documents ??
Thank you for you help
I have a XML file which is define by two XSD schema.
For write the XML file, there are two ways to write the XML file :
(I have to delete the "<" charactere to display the XML file)
First methode to write it :\[code\]?xml version="1.0" encoding="UTF-8" standalone="yes"?>Policy xmlns="http://www.W3C.com/Policy/v3#" xmlns:ns2="http://www.W3C.com /PolicyExtension/v3#">DigestAlg Algorithm="http://test"/>Transforms>Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n20010315"></Transform>/Transforms> ns2:Validation> ns2:ConditionID>1.0.1</ns2:ConditionID> ns2:TConditionID>1.0.2</ns2:TConditionID> /ns2:Validation>/Policy>" \[/code\]second methodes :\[code\]?xml version="1.0" encoding="UTF-8" standalone="yes"?>Policy xmlns="http://www.W3C.com/Policy/v3#">DigestAlg Algorithm="http://test"/>Transforms>Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n20010315"></Transform>/Transforms> Validation xmlns:ns2="http://www.W3C.com/PolicyExtension/v3#"> ConditionID>1.0.1</ns2:ConditionID> TConditionID>1.0.2</ns2:TConditionID> /Validation>/Policy> \[/code\]For pasring my XML files, i use :\[code\]InputStream doc = new FileInputStream(myXMLFile);DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); List<Source> sourceListSchema = new ArrayList<Source>(); sourceListSchema.add(new StreamSource(SignaturePolicy.class.getResourceAsStream(MY_XSD_SCHEMA_1))); sourceListSchema.add(new StreamSource(SignaturePolicy.class.getResourceAsStream(MY_XSD_SCHEMA_2))); Schema schema; try { Source[] sourceTmp = new Source[1]; schema = sf.newSchema(sourceListSchema.toArray(sourceTmp)); } catch (SAXException e) { LogMachine.logger.severe( "SAXException : The schema can not be parse :"+e.getMessage()); } dbf.setIgnoringElementContentWhitespace(true); dbf.setNamespaceAware(true); dbf.setIgnoringComments(true); dbf.setSchema(schema); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); documentPolicy = db.parse(Doc); } catch (ParserConfigurationException e) { LogMachine.logger.severe( "ParserConfigurationException : the file can not be parse by DOM :"+e.getMessage()); } catch (SAXException e) { LogMachine.logger.severe( "SAXException : the file can not be parse by DOM :"+e.getMessage()); } catch (IOException e) { LogMachine.logger.severe( "IOException : the file can not be open like a file :"+e.getMessage()); }\[/code\]When I want to parse this documents with DOM, the first XML file display an error
Exception in thread "main" org.w3c.dom.ls.LSException: The prefix "ns2" for element "ns2:Validation" is not bound.But the second XML file is well parse.Someone can help me to parse the two documents ??
Thank you for you help