[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
RE: [xml-dev] Need help on parsing XSD files
- From: "Michael Kay" <mike@saxonica.com>
- To: "'Neeraj Lal'" <neerajlal48@gmail.com>,"'xml-dev'" <xml-dev@lists.xml.org>
- Date: Fri, 27 Mar 2009 00:28:31 -0000
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
Hi,
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:annotation>
<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:appinfo>
<i:ConformantIndicator>true</i:ConformantIndicator>
</xsd:appinfo>
</xsd:annotation>
<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:annotation>
<xsd:documentation>A data type for a single or set of related actions,
events, or process steps.
</xsd:documentation>
<xsd:complexType
name="WitnessType">
<xsd:annotation>
<xsd:documentation>A data type for a person who has
observed an activity. Builds upon a LEXS Digest
Witness.</xsd:documentation>
<xsd:appinfo>
<i:Base
i:namespace="http://niem.gov/niem/domains/jxdm/4.0"
i:name="WitnessType"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension
base="j:WitnessType">
<xsd:sequence>
<xsd:element
ref="ndexia:WitnessAugmentation" minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<!--
==================================================================
-->
<!-- 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:annotation>
<xsd:documentation>A mode of transportation capable
of flying in the air.</xsd:documentation>
</xsd:annotation>
</xsd:element>
Also, do the SAX/DOM parser ignore the comment
lines of their own?
Finally, how should I resolve the namespaces and
references?
Thanks
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]