I, personally, set the following features and properties for my
requirements and it works:

Features:
http://apache.org/xml/features/validation/schema  to true.
http://xml.org/sax/features/namespaces to true
http://xml.org/sax/features/validation to true

JAXP property:
http://java.sun.com/xml/jaxp/properties/schemaLanguage to http://www.w3.org/2001/XMLSchema


Reinhard Brandst�dter wrote:

Hi!

I'm very unsucessful in validating a XML file against a XSD. I've read several hints about setting the validation features but all I've tried renders either in errors or exceptions.

Here is what I did:

try {
  SAXParserFactory factory = SAXParserFactory.newInstance();
  SAXParser parser = factory.newSAXParser();
  DefaultHandler handler = new ParseErrorHandler();
  XMLReader reader = parser.getXMLReader();

reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation","eventconfigs.xsd";);

  reader.setFeature("http://xml.org/sax/features/validation";, true);
  reader.setFeature("http://xml.org/sax/features/validation/schema";,
                     true);

  parser.parse(cfg_file, handler);
}
catch (SAXException ex) {
  ex.printStackTrace();
}
catch (ParserConfigurationException ex) {
  ex.printStackTrace();
}

When parsing the files (example XML and XSD attached) I get an error:

org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/validation/schema

I've also tried to use a DOMParser but without any sucess.
Thanks for any help on that!

Reinhard


------------------------------------------------------------------------

<?xml version="1.0"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:noNamespaceSchemaLocation="eventconfigs.xsd">
<!-- a default send object -->
<eventconfig>
<event type="send">
</event>
<eventrep>
<class name="visualization.objects.NativeSVG" reuse="true" idstring="sendevents_all">
<svg xmlns="http://www.w3.org/2000/svg";>
<text x="20" y="25" font-family="Verdana" font-size="12" fill="black">
Send Events: ${countstatistics_eventtype_all}
</text>
</svg>
</class>
<class name="visualization.objects.NativeSVG" reuse="true" idstring="sendevents-${processid}">
<svg xmlns="http://www.w3.org/2000/svg";>
<rect x="# 20 + 20*${processid}" y="#300 - 270*(${countstatistics_eventtype_processor}/${countstatistics_eventtype_all})" width="15" height="# 270*(${countstatistics_eventtype_processor}/${countstatistics_eventtype_all})" fill="green"/>
<text x="# 20 + 20*${processid}" y="#290 - 270*(${countstatistics_eventtype_processor}/${countstatistics_eventtype_all})" font-family="Verdana" font-size="10" fill="black"># round(100*${countstatistics_eventtype_processor}/${countstatistics_eventtype_all})</text>
</svg>
</class>
<class name="visualization.objects.NativeSVG" onlyonce="true" idstring="plabelsend-${processid}">
<svg xmlns="http://www.w3.org/2000/svg";>
<text x="# 20 + 20*${processid}" y="#315" font-family="Verdana" font-size="12" fill="black">P${processid}</text>
</svg>
</class>
</eventrep>
</eventconfig>
<!-- a default receive object -->
<eventconfig>
<event type="receive">
</event>
<eventrep>
<class name="visualization.objects.NativeSVG" reuse="true" idstring="recvevents_all">
<svg xmlns="http://www.w3.org/2000/svg";>
<text x="220" y="25" font-family="Verdana" font-size="12" fill="black">
Recv Events: ${countstatistics_eventtype_all}
</text>
</svg>
</class>
<class name="visualization.objects.NativeSVG" reuse="true" idstring="recvevents-${processid}">
<svg xmlns="http://www.w3.org/2000/svg";>
<rect x="# 220 + 20*${processid}" y="# 300 - 270*(${countstatistics_eventtype_processor}/${countstatistics_eventtype_all})" width="15" height="# 270*(${countstatistics_eventtype_processor}/${countstatistics_eventtype_all})" fill="red"/>
<text x="# 220 + 20*${processid}" y="# 290 - 270*(${countstatistics_eventtype_processor}/${countstatistics_eventtype_all})" font-family="Verdana" font-size="10" fill="black"># round(100*${countstatistics_eventtype_processor}/${countstatistics_eventtype_all})</text>
</svg>
</class>
<class name="visualization.objects.NativeSVG" onlyonce="true" idstring="plabelrecv-${processid}">
<svg xmlns="http://www.w3.org/2000/svg";>
<text x="# 220 + 20*${processid}" y="#315" font-family="Verdana" font-size="12" fill="black">P${processid}</text>
</svg>
</class>
</eventrep>
</eventconfig>
</events>


------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
        <xs:element name="events">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element name="eventconfig" 
maxOccurs="unbounded">
                                        <xs:complexType>
                                                <xs:sequence>
                                                        <!-- the event 
representation -->
                                                        <xs:element 
name="event">
                                                                <xs:complexType 
mixed="true">
                                                                        <xs:choice 
minOccurs="0" maxOccurs="unbounded">
                                                                                
<!-- the event's parameters -->
                                                                                <xs:element 
name="parameter">
                                                                                      
  <xs:complexType>
                                                                                                
<xs:attribute name="name" use="required"/>
                                                                                                <xs:attribute 
name="value" type="xs:integer" use="required"/>
                                                                                                
<xs:attribute name="min" type="xs:integer"/>
                                                                                                
<xs:attribute name="max" type="xs:integer"/>
                                                                                      
  </xs:complexType>
                                                                                
</xs:element>
                                                                        
</xs:choice>
                                                                        <xs:attribute name="type" 
type="xs:string" use="required"/>
                                                                        <xs:attribute 
name="processid" type="xs:integer"/>
                                                                
</xs:complexType>
                                                        </xs:element>
                                                        <!-- the event 
representation -->
                                                        <xs:element 
name="eventrep">
                                                                <xs:complexType>
                                                                        
<xs:sequence>
                                                                                
<!-- the class for the graphical object -->
                                                                                <xs:element 
name="class" maxOccurs="unbounded">
                                                                                      
  <xs:complexType>
                                                                                      
          <xs:sequence>
                                                                                      
                  <xs:any/>
                                                                                      
          </xs:sequence>
                                                                                                <xs:attribute 
name="name" type="xs:string" use="required"/>
                                                                                                
<xs:attribute name="reuse" type="xs:boolean"/>
                                                                                                
<xs:attribute name="idstring" type="xs:string"/>
                                                                                                
<xs:attribute name="onlyonce" type="xs:boolean"/>
                                                                                      
  </xs:complexType>
                                                                                
</xs:element>
                                                                        
</xs:sequence>
                                                                
</xs:complexType>
                                                        </xs:element>
                                                </xs:sequence>
                                        </xs:complexType>
                                </xs:element>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
</xs:schema>



------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to