Bonjour!
j'ai l,exception mentionnée dans le sujet quand je je tente de parser un xml associé a un schema XSD
PVI voici le XSD, le XML et un bout du code JAVA servant à parser:
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.netbeans.org/schema/blog" xmlns:tns="http://xml.netbeans.org/schema/blog" elementFormDefault="qualified"> <!-- Définition du ROOT elem 'Blog' --> <xs:annotation> <!-- DOC--> <xs:documentation> xs pour le blog engine XML </xs:documentation> </xs:annotation> <xs:element name="Blog"> <xs:complexType> <xs:sequence> <!-- Début de définition de l'élément Entry --> <xs:element name="Entry " minOccurs="0" maxOccurs="unbounded"> <xs:annotation> <xs:documentation> L'élément Entry représente un billet donné </xs:documentation> </xs:annotation> <!-- DOC--> <xs:complexType> <xs:sequence> <xs:element name="Text"/> <xs:element name="Resume" minOccurs="0" maxOccurs="unbounded"/> <!-- Début de définition de l'élément Comment --> <xs:element name="Comment" minOccurs="0" maxOccurs="unbounded"> <xs:annotation> <xs:documentation> L'élément comment représente un commentaire d'un lecteur à propos d'un billet donné </xs:documentation> </xs:annotation> <!-- DOC--> <xs:complexType> <xs:sequence> <xs:element name="CommentText" maxOccurs="1"/> </xs:sequence> <xs:attribute name="date" type="xs:date" use="required"/> <xs:attribute name="author" type="xs:string"/> <xs:attribute name="webPage" type="xs:anyURI"/> <!-- Début de séquence définissant les sous éléments de Comment --> <!-- attributs de l'élément Comment--> <!-- Fin des attributs de l'élément comment--> </xs:complexType> </xs:element> <!-- Fin de séquence définissant les sous éléments de Comment --> </xs:sequence> <xs:attribute name="date" type="xs:date" use="required"/> <xs:attribute name="categoryHash" type="xs:integer" default="0"/> <xs:attribute name="allowComments" type="xs:boolean" default="false"/> <xs:attribute name="hash" type="xs:integer"/> <xs:attribute name="commentsCounts" type="xs:integer" default="0"/> <!-- Début de séquence définissant les sous éléments de Entry --> <!-- Fin de séquence définissant les sous éléments de Entry --> <!-- attributs de l'élément Entry--> <!-- Fin des attributs de l'élément Entry--> </xs:complexType> </xs:element> <!-- Fin de définition de l'élément Entry --> <!-- Début de définition de l'élément Category --> <xs:element name="Category" minOccurs="0" maxOccurs="unbounded"> <xs:annotation> <xs:documentation> L'élément Categoy représente une catégorie pour un billet donné </xs:documentation> </xs:annotation> <!-- DOC--> <xs:complexType> <xs:attribute name="hash" type="xs:integer" default="0"/> <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="description" type="xs:string"/> </xs:complexType> </xs:element> </xs:sequence> <!-- Début de séquence définissant les sous éléments du Blog --> <!-- Fin de séquence définissant les sous éléments du Blog --> </xs:complexType> </xs:element> <!-- Fin du ROOT element--> </xs:schema>
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?xml version="1.0" encoding="UTF-8"?> <site:Blog xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:site='http://xml.netbeans.org/schema/blog' xsi:schemaLocation='http://xml.netbeans.org/schema/blog blog.xsd'> <site:Entry date="2007-09-07" categoryHash="222" allowComments="true" hash="26657200"> <site:Text>Texte</site:Text> <site:Resume>R&eacute;sum&eacute; du billet non disponible</site:Resume> </site:Entry> <site:Category hash="123" description="Une desciption" name="Cat1"/> </site:Blog>
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 public static final String NAMESPACES_FEATURE = "http://xml.org/sax/features/namespaces"; public static final String VALIDATION_FEATURE = "http://xml.org/sax/features/validation"; public static final String SCHEMA_VALIDATION_FEATURE = "http://apache.org/xml/features/validation/schema"; public static final String SCHEMA_FULL_CHECKING_FEATURE = "http://apache.org/xml/features/validation/schema-full-checking"; // public static final String DYNAMIC_VALIDATION_FEATURE = // "http://apache.org/xml/features/validation/dynamic"; // // public static final String LOAD_EXTERNAL_DTD_FEATURE = // "http://apache.org/xml/features/nonvalidating/load-external-dtd"; // // public static final String JAXP_SCHEMA_LANGUAGE = // "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; // public static final String W3C_XML_SCHEMA = // "http://www.w3.org/2001/XMLSchema"; public static final String EXTERNAL_XSD="http://apache.org/xml/properties/external-SchemaLocation"; public static final String DOCUMENT_IMPLEMENTATION_PROPERTY = "http://apache.org/xml/properties/dom/document-class-name"; public static final String DOCUMENT_PSVI_IMPLEMENTATION = "org.apache.xerces.dom.PSVIDocumentImpl"; boolean _validating; /** * Constructor for Xerxes loader. */ public CustomDomLoader() { _validating = false; } /** * The Xerces loader loads the XML docuemnt * @param in is the input stream. * @throws DOMLoaderException DOM loader exception. * @return The loaded document. */ // XXX: fix error reporting public Document load(InputStream in) throws DOMLoaderException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); //factory.setAttribute(EXTERNAL_XSD,"http://xml.netbeans.org/schema/blog /home/laurent/Programming tools/blog/blog.xsd"); factory.setValidating(_validating); factory.setAttribute(SCHEMA_VALIDATION_FEATURE, new Boolean(_validating)); factory.setAttribute(DOCUMENT_IMPLEMENTATION_PROPERTY, DOCUMENT_PSVI_IMPLEMENTATION); // factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); try { DocumentBuilder builder = factory.newDocumentBuilder(); if(_validating) { builder.setErrorHandler(new ErrorHandler() { public void fatalError(SAXParseException e) throws SAXException { throw e; } public void error(SAXParseException e) throws SAXParseException { throw e; } public void warning(SAXParseException e) throws SAXParseException { throw e; // XXX } }); } return builder.parse(in); } catch(SAXException e) { System.out.println("Sax exception: "+e.getMessage()); e.printStackTrace(); return null; } catch(ParserConfigurationException e) { throw new DOMLoaderException("Parser configuration exception: " + e.getMessage()); } catch(IOException e) { throw new DOMLoaderException("IO exception: " + e.getMessage()); } }
Avez-vous des idées du pourquoi j'obtiens cette exception ?
Si vous avez besoin de plus d'infos n'hésitez pas
Merci!
Partager