[jdom-interest] Re: Problem extracting include elements from an XML schema.
Bart Read
bart.read at uk.lionbioscience.com
Wed Jul 30 06:26:50 PDT 2003
Dear All,
We are developing a tool for a bioinformatics system that allows the
user to interact directly with XML schemas. My code loads a schema and
creates a JDOM tree just as if it were a normal XML document. However,
here's the problem: I'm trying to get the include child elements from
the root element but always the list I'm returned is empty. Checking
using the NetBeans debugger shows that the JDOM Document object matches
the underlying schema.
Right, so here's my code:
Document schema = . // This code gets the schema from wherever it
happens to be and
// gives it to JDOM
Element root = schema.getRootElement();
Namespace ns = root.getNamespace();
List includes = root.getChildren( "include", ns );
The List in the last line of code is always empty, this is even the case
when I don't specify the namespace. But when I use the debugger it
clearly shows that the namespace of the root element is the same as that
of the child elements, including the include elements. Does anybody
have any idea what I'm doing wrong? I'm using a test schema from the
Ordinance Survey in the UK, which is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<schema
targetNamespace="http://www.ordnancesurvey.co.uk/xml/namespaces/osgb"
xmlns:osgb="http://www.ordnancesurvey.co.uk/xml/namespaces/osgb"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified"
attributeFormDefault="unqualified" version="2.4">
<annotation>
<appinfo>OSComplexTypes.xsd 2.4 2003/01</appinfo>
<documentation xml:lang="en">Ordnance Survey, (c) Crown
Copyright. All Rights Reserved January 2003.</documentation>
<documentation xml:lang="en">See
http://www.ordnancesurvey.co.uk/xml/schema for guidelines and related
information</documentation>
<documentation xml:lang="en">This schema defines the
complex types used as properties on features.</documentation>
</annotation>
<!-- include constructs from other OS schemas -->
<include schemaLocation="OSQueryResult.xsd"/>
<include schemaLocation="OSSimpleTypes.xsd"/>
<include schemaLocation="OSMeasures.xsd"/>
<!--import OGC constructs-->
<import namespace="http://www.opengis.net/gml"/>
<!-- import xml:lang construct. This is sourced from :
http://www.w3.org/2001/03 -->
<import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="xml.xsd"/>
<!--
================================================================
Complex Type Definitions
================================================================
-->
<complexType name="addressStatusType">
<sequence>
<element name="matchStatus"
type="osgb:matchStatusType"/>
<element name="physicalStatus"
type="osgb:physicalStatusType"/>
<element name="positionalQuality"
type="osgb:positionalQualityType"/>
<element name="structureType"
type="osgb:structureTypeType"/>
</sequence>
</complexType>
<complexType name="changeHistoryType">
<sequence>
<element name="changeDate" type="date"/>
<element name="reasonForChange"
type="osgb:reasonForChangeType"/>
</sequence>
</complexType>
<group name="dateRange">
<choice>
<element name="namedDate" type="string"/>
<element name="specifiedDate">
<complexType>
<sequence>
<element
name="startDate" type="gMonthDay"/>
<element name="endDate"
type="gMonthDay"/>
</sequence>
</complexType>
</element>
</choice>
</group>
<complexType name="dateTimeQualifierType">
<choice>
<element name="namedPeriod" type="string"/>
<element name="specifiedPeriod" minOccurs="0">
<complexType>
<sequence>
<group
ref="osgb:dateRange" minOccurs="0" maxOccurs="unbounded"/>
<element name="day"
minOccurs="0" maxOccurs="unbounded" type="string"/>
<group
ref="osgb:timeRange" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</choice>
</complexType>
<complexType name="directedLinkAssociationType">
<annotation>
<documentation xml:lang="en">
+ identifies that the relationship refers to the edge in its
natural direction,
i.e. the direction that the geometry is in. - identifies that
it is in the opposite
direction, i.e. the direction opposite to the geometric
coordinates.
</documentation>
</annotation>
<complexContent>
<extension base="gml:FeatureAssociationType">
<attribute name="orientation"
type="osgb:signType" use="required"/>
</extension>
</complexContent>
</complexType>
<complexType name="directedNodeAssociationType">
<complexContent>
<extension base="gml:FeatureAssociationType">
<attribute name="orientation"
type="osgb:signType" use="optional"/>
<attribute name="gradeSeparation"
type="integer" use="optional" default="0"/>
</extension>
</complexContent>
</complexType>
<complexType name="environmentQualifierType">
<sequence>
<element name="instruction" minOccurs="0">
<simpleType>
<restriction base="string">
<enumeration
value="Access Limited To"/>
<enumeration
value="Mandatory Turn"/>
<enumeration value="No
Entry"/>
<enumeration value="No
Turn"/>
<enumeration value="One
Way"/>
<enumeration
value="Access Prohibited To"/>
</restriction>
</simpleType>
</element>
<element name="classification" minOccurs="0"
maxOccurs="unbounded" type="string"/>
</sequence>
</complexType>
<complexType name="heightAboveDatumType">
<sequence>
<element name="heightAboveDatum" type="double"/>
<element name="accuracyOfHeightAboveDatum"
type="osgb:accuracyOfPositionType"/>
</sequence>
</complexType>
<complexType name="heightAboveGroundLevelType">
<sequence>
<element name="heightAboveGroundLevel"
type="double"/>
<element name="accuracyOfHeightAboveGroundLevel"
type="osgb:accuracyOfPositionType"/>
</sequence>
</complexType>
<complexType name="languageQualifiedString">
<annotation>
<documentation xml:lang="en">
the xml:lang attribute specifies the language of the enclosed
text according
to the ISO 639-1 specification.
en : English
cy : Welsh
gd : Gaelic; Scottish Gaelic.
</documentation>
</annotation>
<simpleContent>
<extension base="string">
<attribute ref="xml:lang" use="optional"
default="en"/>
</extension>
</simpleContent>
</complexType>
<complexType name="nodeAssociationType">
<complexContent>
<extension base="gml:FeatureAssociationType">
<attribute name="gradeSeparation"
type="integer" use="optional" default="0"/>
</extension>
</complexContent>
</complexType>
<complexType name="postalAddressType">
<sequence>
<element name="organisation" type="string"
minOccurs="0"/>
<element name="department" type="string"
minOccurs="0"/>
<element name="POBox" type="string"
minOccurs="0"/>
<element name="subBuildingName" type="string"
minOccurs="0"/>
<element name="buildingName" type="string"
minOccurs="0"/>
<element name="buildingNumber" type="string"
minOccurs="0"/>
<element name="dependentThoroughfare"
type="string" minOccurs="0"/>
<element name="thoroughfare" type="string"
minOccurs="0"/>
<element name="doubleDependentLocality"
type="string" minOccurs="0"/>
<element name="dependentLocality" type="string"
minOccurs="0"/>
<element name="postTown" type="string"
minOccurs="0"/>
<element name="postCode"
type="osgb:postCodeType"/>
<element name="deliveryPointSuffix"
type="osgb:deliveryPointSuffixType" minOccurs="0"/>
</sequence>
<attribute name="nonGeographic" type="boolean"
use="optional" default="false"/>
</complexType>
<complexType name="positionalQualityType">
<simpleContent>
<extension
base="osgb:positionalQualityStringType">
<attribute name="accuracy"
type="osgb:positionalQualityAccuracyType" use="required"/>
</extension>
</simpleContent>
</complexType>
<complexType name="postCodeType">
<simpleContent>
<extension base="osgb:postCodeStringType">
<attribute name="type"
type="osgb:postCodeTypeType" use="optional" default="Small"/>
</extension>
</simpleContent>
</complexType>
<complexType name="textRenderingType">
<sequence>
<element name="anchorPosition"
type="unsignedByte"/>
<element name="font" type="unsignedByte"/>
<element name="height" type="float"/>
<element name="orientation"
type="unsignedShort"/>
</sequence>
</complexType>
<group name="timeRange">
<choice>
<element name="namedTime" type="string"/>
<element name="specifiedTime">
<complexType>
<sequence>
<element
name="startTime" type="time"/>
<element name="endTime"
type="time"/>
</sequence>
</complexType>
</element>
</choice>
</group>
<complexType name="vehicleQualifierType">
<sequence>
<element name="type" minOccurs="0"
maxOccurs="unbounded">
<complexType>
<simpleContent>
<extension
base="string">
<attribute
name="exceptFor" type="boolean"/>
</extension>
</simpleContent>
</complexType>
</element>
<element name="load" minOccurs="0"
maxOccurs="unbounded">
<complexType>
<simpleContent>
<extension
base="string">
<attribute
name="exceptFor" type="boolean"/>
</extension>
</simpleContent>
</complexType>
</element>
<element name="use" minOccurs="0"
maxOccurs="unbounded">
<complexType>
<simpleContent>
<extension
base="string">
<attribute
name="exceptFor" type="boolean"/>
</extension>
</simpleContent>
</complexType>
</element>
<element name="maxHeight" minOccurs="0"
type="osgb:MetresMeasureType"/>
<element name="maxCompositeHeight" minOccurs="0"
type="osgb:ImperialMeasureType"/>
</sequence>
</complexType>
</schema>
I'd be incredibly grateful for any assistance anybody could offer.
Many thanks,
Bart
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030730/b3c020a4/attachment.htm
More information about the jdom-interest
mailing list