You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Ken Gettler <kg...@sonicsoftware.com> on 2001/09/24 16:08:57 UTC
Re: Problem parsing schema with xerces 141 and 143 - bug
I was able to parse xsd file by setting validation=false in parser. For the
time being I'm using XMLSpy to prevalidate any xsd files destined for the
xerces code. Assume that this is a xerces bug - surprised that no one else
has seen it.
Ken
Hayden Marchant wrote:
> Hi Ken,
>
> I'm new to this group, but I noticed your posting: Are you parsing XML
> Schema documents using Xerces? I need to do the same thing. I was hoping
> that there was a specific API out there that represents a Schema, other
> than parsing the XML and working it out. I assume that you looked and
> did not find anything? If so, then how did you approach the problem -
> are you just parsing the XML Schema doc yourself and analyzing for all
> the types of XML Schema language constructs? Did you look ever think of
> using org.apache.xerces.validators.schema.TraverseSchema class in
> Xerces?
>
> I'm about to embark on the same type of head-ache of parsing XML schemas
> so I would really appreciate soeme feedback on problems you encountered
> doing this.
>
> Thanks,
> Hayden
>
> -----Original Message-----
> From: Ken Gettler [mailto:kgettler@sonicsoftware.com]
> Sent: Thursday, September 20, 2001 9:08 PM
> To: xerces developer group
> Subject: Problem parsing schema with xerces 141 and 143
>
> I am attempting to parse xsd documents with the objective of finding
> elements in user-defined xsd files. So far I have had no luck. Keep
> getting exceptions thrown during the parse(). Finally I took one of the
>
> sample xsd files that comes with XML Spy 4.0beta3 and while XML Spy
> could parse the file, I could not with xerces 1.4.1. Is there something
>
> that I am doing incorrectly or is this a parser problem? My code is as
> follows:
>
> Thanks
> Ken
>
> Element element = null;
>
> try
> {
> DocumentBuilder builder = DOMUtils.getDocumentBuilder(true);
>
> Document document =
> builder.parse(URLUtil.makeFileURL(xmlfile));
> element = document.getDocumentElement();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> return element;
>
> where DOMUtils method is:
> public static DocumentBuilder getDocumentBuilder(boolean validating)
> throws ParserConfigurationException
> {
> DocumentBuilderFactory factory =
> DocumentBuilderFactory.newInstance();
> factory.setValidating(validating);
> factory.setNamespaceAware(true);
> DocumentBuilder builder = factory.newDocumentBuilder();
> builder.setErrorHandler(errorHandler);
> return builder;
> }
>
> and,
> private static ErrorHandler errorHandler = new
> DOMParserErrorHandlerImpl();
>
> EXCEPTION:
> ==========
> org.xml.sax.SAXParseException: An invalid second ':' was found in the
> element type or attribute name.
> at
> org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1196)
> at
> org.apache.xerces.framework.XMLDocumentScanner.scanAttributeName(XMLDocu
> mentScanner.java:2143)
>
> at
> org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentSc
> anner.java:1807)
>
> at
> org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatc
> h(XMLDocumentScanner.java:1005)
>
> at
> org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScan
> ner.java:381)
>
> at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1081)
> at
> org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.jav
> a:195)
>
> at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:184)
>
> at
> com.sonicsw.xs.config.XSFileConfig.readXMLFile(XSFileConfig.java:153)
> at com.sonicsw.xs.config.XSFileConfig.main(XSFileConfig.java:170)
> Exception caught by debugger. Exception: java.lang.NullPointerException
> Exception caught by debugger. Exception: java.lang.NullPointerException
> Exception caught by debugger. Exception: java.lang.NullPointerException
>
> Sample XSD used:
> =============
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- edited with XML Spy v4.0 NT beta 2 build Jul 24 2001
> (http://www.xmlspy.com) by Vladislav Gavrielov (Altova) -->
> <!--W3C Schema generated by XML Spy v3.5 NT (http://www.xmlspy.com)-->
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified"
> version="2.1">
> <xsd:element name="bold">
> <xsd:complexType mixed="true">
> <xsd:choice minOccurs="0" maxOccurs="unbounded">
> <xsd:element ref="italic"/>
> <xsd:element ref="bold"/>
> </xsd:choice>
> </xsd:complexType>
> </xsd:element>
> <xsd:element name="copyright" type="TextualData"/>
> <xsd:element name="datasheet">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="documentid">
> <xsd:annotation>
> <xsd:documentation>Document IDs are assigned by central IT Admin -
>
> call 555-1212 for a new ID</xsd:documentation>
> </xsd:annotation>
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:pattern value=".{3}-.{4}-.*"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
> <xsd:element name="manufacturer" type="xsd:string"/>
> <xsd:element name="website" type="xsd:anyURI"/>
> <xsd:element name="productline" type="xsd:string"/>
> <xsd:element ref="security"/>
> <xsd:element ref="tracking"/>
> <xsd:element ref="title"/>
> <xsd:element ref="description"/>
> <xsd:element ref="diagrams"/>
> <xsd:element ref="models"/>
> <xsd:element ref="copyright"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
> <xsd:element name="description" type="TextualData"/>
> <xsd:element name="diagrams">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="diagram" maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element ref="title"/>
> <xsd:element ref="source"/>
> <xsd:element ref="description" minOccurs="0"/>
> </xsd:sequence>
> <xsd:attribute name="kind">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="drawing"/>
> <xsd:enumeration value="3d"/>
> <xsd:enumeration value="chart"/>
> <xsd:enumeration value="photo"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:attribute>
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
> <xsd:element name="italic">
> <xsd:complexType mixed="true">
> <xsd:choice minOccurs="0" maxOccurs="unbounded">
> <xsd:element ref="italic"/>
> <xsd:element ref="bold"/>
> </xsd:choice>
> </xsd:complexType>
> </xsd:element>
> <xsd:element name="models">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="model" maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="Name" type="xsd:string"/>
> <xsd:element name="MaxTakeoffWeight" type="xsd:int">
> <xsd:annotation>
> <xsd:documentation>Specify in lb</xsd:documentation>
> </xsd:annotation>
> </xsd:element>
> <xsd:element name="MaxLandingWeight" type="xsd:int"/>
> <xsd:element name="MaxZeroFuelWeight" type="xsd:int"/>
> <xsd:element name="EngineOfferings" type="xsd:string"/>
> <xsd:element name="FuelCapacity" type="xsd:int"/>
> <xsd:element name="CruiseMach" type="xsd:decimal"/>
> <xsd:element name="Passengers">
> <xsd:simpleType>
> <xsd:restriction base="xsd:short">
> <xsd:minInclusive value="200"/>
> <xsd:maxInclusive value="900"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
> <xsd:element name="DesignRange" type="xsd:short"/>
> <xsd:element name="LowerHoldVolume" type="xsd:short"/>
> <xsd:element name="Pallets" type="xsd:byte"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
> <xsd:element name="para">
> <xsd:complexType mixed="true">
> <xsd:choice minOccurs="0" maxOccurs="unbounded">
> <xsd:element ref="bold"/>
> <xsd:element ref="italic"/>
> </xsd:choice>
> </xsd:complexType>
> </xsd:element>
> <xsd:element name="security">
> <xsd:annotation>
> <xsd:documentation>Define security classification as per corporate
> guidelines document B98265-Z0</xsd:documentation>
> </xsd:annotation>
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="classification">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="public"/>
> <xsd:enumeration value="confidential"/>
> <xsd:enumeration value="eyes only"/>
> <xsd:enumeration value="restricted"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
> <xsd:element name="level">
> <xsd:simpleType>
> <xsd:restriction base="xsd:byte">
> <xsd:minInclusive value="1"/>
> <xsd:maxInclusive value="3"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
> <xsd:element name="effective" type="xsd:date"/>
> <xsd:element name="use">
> <xsd:complexType>
> <xsd:attribute name="internal" type="xsd:boolean"/>
> <xsd:attribute name="external" type="xsd:boolean"/>
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
> <xsd:element name="source">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:pattern value=".*\.(gif|jpg)"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
> <xsd:element name="title">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:maxLength value="25"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
> <xsd:element name="tracking">
> <xsd:annotation>
> <xsd:documentation>All editors are required to log changes to each
> production document</xsd:documentation>
> </xsd:annotation>
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="modification" maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="date" type="xsd:date"/>
> <xsd:element name="time" type="xsd:time"/>
> <xsd:element name="by" type="xsd:string"/>
> <xsd:element name="department">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="Marketing"/>
> <xsd:enumeration value="IT"/>
> <xsd:enumeration value="IT Admin"/>
> <xsd:enumeration value="Engineering"/>
> <xsd:enumeration value="Graphics Design"/>
> <xsd:enumeration value="Auditing"/>
> <xsd:enumeration value="Aerospace"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
> <xsd:element name="status">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="in progress"/>
> <xsd:enumeration value="for review"/>
> <xsd:enumeration value="final"/>
> <xsd:enumeration value="for editing"/>
> <xsd:enumeration value="for archive"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
> <xsd:element name="changes" type="xsd:string"/>
> </xsd:sequence>
> <xsd:attribute name="operation" use="required">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="approved"/>
> <xsd:enumeration value="created"/>
> <xsd:enumeration value="deleted"/>
> <xsd:enumeration value="edited"/>
> <xsd:enumeration value="rejected"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:attribute>
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
> <xsd:complexType name="TextualData">
> <xsd:sequence>
> <xsd:element ref="para" maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:schema>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org