OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
RE: [xml-dev] Need help on parsing XSD files

SAX is a very low-level programming interface for XML parsing. DOM is slightly more programmer-friendly but not much. I would suggest you do your processing in a higher-level declarative language such as XSLT or XQuery.
Even then, I would tend to ask questions about what you are trying to achieve. Extracting information from XSD schema documents is not easy even if you are expert in the tools that you are using, because there are many different ways of writing the same schema in XSD - you don't just have to parse the document to get this right, you have to do some quite sophisticated processing on it. You might be better off loading the schema using software that already knows how to do this (for example the Saxon or Xerces schema processors) and then using the processor's API to access the information at the level of the schema component model.
Michael Kay

From: Neeraj Lal [mailto:neerajlal48@gmail.com]
Sent: 26 March 2009 15:57
To: xml-dev
Subject: [xml-dev] Need help on parsing XSD files


I'm new to XML and need some help on parsing large XSD files which include namespaces and references to other XSD files.
Which parser is best for this purpose, SAX or DOM?

I started with SAX parser but I'm facing some difficulties with it. When I try to parse this:
<xsd:element ref="ndexia:WitnessAugmentation" minOccurs="0"/>

I do not get the data in this element. Since, this element does not have a proper ending tag like: </xsd:element>
will the ' endElement(String uri, String localName, String qName) ' end element method detect the end of element?

How to extract the ref and minOccurs values from the above element?

The xsd that I'm using has several of the following elements:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://niem.gov/niem/niem-core/2.0" version="1" xmlns:niem-xsd="http://niem.gov/niem/proxy/xsd/2.0" xmlns:i="http://niem.gov/niem/appinfo/2.0" xmlns:usps="http://niem.gov/niem/usps_states/2.0" xmlns:census="http://niem.gov/niem/census/2.0" xmlns:unece="http://niem.gov/niem/unece_rec20-misc/2.0" xmlns:fips_10-4="http://niem.gov/niem/fips_10-4/2.0" xmlns:fips_6-4="http://niem.gov/niem/fips_6-4/2.0" xmlns:s="http://niem.gov/niem/structures/2.0" xmlns:iso_639-3="http://niem.gov/niem/iso_639-3/2.0" xmlns:iso_4217="http://niem.gov/niem/iso_4217/2.0" xmlns:fbi="http://niem.gov/niem/fbi/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:nc="http://niem.gov/niem/niem-core/2.0">
    <xsd:documentation>NIEM Core includes both Universal (U) and Common (C) components.  The identities for U and C components in Core are maintained with metadata.</xsd:documentation>
  <xsd:import schemaLocation="../../structures/2.0/structures.xsd" namespace="http://niem.gov/niem/structures/2.0"/>
  <xsd:import schemaLocation="../../proxy/xsd/2.0/xsd.xsd" namespace="http://niem.gov/niem/proxy/xsd/2.0"/>
  <xsd:import schemaLocation="../../unece_rec20-misc/2.0/unece_rec20-misc.xsd" namespace="http://niem.gov/niem/unece_rec20-misc/2.0"/>
  <xsd:import schemaLocation="../../usps_states/2.0/usps_states.xsd" namespace="http://niem.gov/niem/usps_states/2.0"/>
  <xsd:complexType name="ActivityType">
      <xsd:documentation>A data type for a single or set of related actions, events, or process steps.
<xsd:complexType name="WitnessType">
            <xsd:documentation>A data type for a person who has observed an activity.  Builds upon a LEXS Digest Witness.</xsd:documentation>
                <i:Base i:namespace="http://niem.gov/niem/domains/jxdm/4.0" i:name="WitnessType"/>
            <xsd:extension base="j:WitnessType">
                    <xsd:element ref="ndexia:WitnessAugmentation" minOccurs="0"/>
    <!-- ================================================================== -->
    <!-- Entity Elements -->
    <!-- ================================================================== -->
    <!-- These elements are all substitutable for the N-DEx Entity object, so that all high level objects that may appear in a report are grouped together without having to be in a specific order. -->
    <!-- ================================================================== -->
    <xsd:element name="Aircraft" type="ndexia:AircraftType" substitutionGroup="ndexia:Entity" nillable="true">
            <xsd:documentation>A mode of transportation capable of flying in the air.</xsd:documentation>

Also, do the SAX/DOM parser ignore the comment lines of their own?
Finally, how should I resolve the namespaces and references?


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS