Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2009, 10:16 PM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default namespace issue. xml and xsd

Hi. I seem not to be able to figure this out for myself unfortunately, so hopefully someone here will be able to put me right.

I am creating a schema (.xsd) for the template xml file for my xml application. I can correctly validate my xsd against any of the elements or attributes within my namespace, however, I am having a problem when validating some elements from another namespace, GML.

The xsd is not reporting any problems - this being the relevant extract:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" elementFormDefault="qualified"
    xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:geo="http://www.dur.ac.uk/geo-engineering"
    targetNamespace="http://www.dur.ac.uk/geo-engineering" xmlns:diggs="http://www.diggml.com">
    
    <xs:import namespace="http://www.opengis.net/gml" schemaLocation="./base/gmlBase.xsd"/>

<xs:element name="caseDescription">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="general">
                                            <xs:complexType>
                                                <xs:sequence>
                                                    <xs:element ref="gml:name" minOccurs="0" maxOccurs="unbounded"/>
                                                    <xs:element ref="gml:description" minOccurs="0" maxOccurs="unbounded"/>
                                                    <xs:element name="altitude">
                                                        <xs:complexType>
                                                            <xs:simpleContent>
                                                                <xs:extension base="xs:integer">
                                                                    <xs:attribute name="unit" type="xs:token"/>
                                                                </xs:extension>
                                                            </xs:simpleContent>
                                                        </xs:complexType>
                                                    </xs:element>
                                                    <xs:element name="city" type="xs:string"/>
                                                </xs:sequence>
                                            </xs:complexType>
                                        </xs:element>
                                        <xs:element name="otherInformation" type="xs:string"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                       </xs:schema>
As I said, this gives me the green light so all seems to find external schema references ok etc.

Here is the offending xml file extract:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="SlopeXHTML.xsl"?>
<geo:slopeData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.dur.ac.uk/geo-engineering Short.xsd"
 xmlns:gml="http://www.opengis.com/gml/3.2"
 xmlns:geo="http://www.dur.ac.uk/geo-engineering"
 xmlns:xlink="http://www.w3.org/1999/xlink">

        <geo:caseDescription>
            <geo:general>
                <gml:name>Illgill Head</gml:name>
                <gml:description>Tension Cracks</gml:description>
                <geo:altitude unit="m">749</geo:altitude>
                <geo:city>Lake District</geo:city>
            </geo:general>
            <geo:otherInformation />
        </geo:caseDescription>
</geo:slopeData>
I receive the error:
E [Xerces] cvc-complex-type.2.4.a: Invalid content was found starting with element 'gml:name'. One of '{"http://www.opengis.net/gml":name, "http://www.opengis.net/gml":description, "http://www.dur.ac.uk/geo-engineering":altitude}' is expected.

If I delete <gml:name> and <gml:description> from the xml then it validates fine. It seems like a very strange error to me as been as the xsd file can find what it needs to and validates.

Note that these are extracts from a much larger file but these extracts should work by themselves.

Thanks for any help.
 
Old April 7th, 2009, 03:58 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The schema is defined to validate elements in namespace http://www.opengis.net/gml but your instance documents has elements in namespace http://www.opengis.com/gml/3.2
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
jamesdurham (April 7th, 2009)
 
Old April 7th, 2009, 09:33 AM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

Thanks for your reply.

I had noticed the change in url before and had tried deleting the /3.2 from the end, but what I hadn't noticed (until you pointed it out) was that one was .net and the other was .com! How strange because both have been copied from official documents supplied by gml.

Thanks for pointing it out, it has now solved that problem and hopefully I can get this schema finished ready for putting my work online.
 
Old April 7th, 2009, 06:57 PM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

Hi again. I have nearly completed the schema but cannot seem to be rid of this one error.

I originally thought it was because I had used xs:import for two GML schemas, with both under the same namespace and I found out that is not allowed. I therefore created a new schema and used xs:include in order to include both of those schemas and then in my main application schema I could then use a single xs:import for that namespace. (Beats me why they haven't already created one all-mighty xsd for this purpose..but anyway.)

I am receiving the following error:
E [Xerces] src-element.2.2: Since 'gml:Point' contains the 'ref' attribute, its content must match (annotation?). However, 'complexType' was found.

Here is the xml extract (which is based on the hierarchy already shown previously):
Code:
                <geo:location>
                    <gml:Point gml:id="slopePeak">
                        <gml:pos>316865 504940</gml:pos>
                        <geo:lat>54.432893</geo:lat>
                        <geo:long>-3.283085</geo:long>
                    </gml:Point>
                </geo:location>
Here is the schema extract:
Code:
<xs:element name="location" minOccurs="0" maxOccurs="1">
   <xs:complexType>
      <xs:sequence>
         <xs:element ref="gml:Point">
            <xs:complexType>
               <xs:sequence>
                  <xs:element ref="gml:pos" />
                  <xs:element name="lat" minOccurs="0" maxOccurs="1">
                     <xs:complexType>
                        <xs:simpleContent>
                           <xs:extension base="xs:decimal" />
                        </xs:simpleContent>
                     </xs:complexType>
                  </xs:element>
                  <xs:element name="long" minOccurs="0" maxOccurs="1">
                     <xs:complexType>
                        <xs:simpleContent>
                            <xs:extension base="xs:decimal" />
                        </xs:simpleContent>
                     </xs:complexType>
                  </xs:element>
                  <xs:attribute name="gml:id" type="xs:token"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
      </xs:sequence>
   </xs:complexType>
</xs:element>
The external schema file that I created in order to contain the required schema files I need but in one, has these three inclusions:
Code:
	<include schemaLocation="gmlBase.xsd"/>
	<include schemaLocation="geometryBasic0d1d.xsd"/>
	<include schemaLocation="basicTypes.xsd"/>
This file is then referenced successfully in to my application schema.
I think that gml:Point comes is defined in that middle file and looks like this:
Code:
<element name="Point" type="gml:PointType" substitutionGroup="gml:_GeometricPrimitive"/>
	<!-- ============================================================== -->
	<complexType name="PointType">
		<annotation>
			<documentation>A Point is defined by a single coordinate tuple.</documentation>
		</annotation>
		<complexContent>
			<extension base="gml:AbstractGeometricPrimitiveType">
				<sequence>
					<choice>
						<annotation>
							<documentation>GML supports two different ways to specify the direct poisiton of a point. 1. 
                                                                                The "pos" element is of type DirectPositionType.
                                                        </documentation>
						</annotation>
						<element ref="gml:pos"/>
					</choice>
				</sequence>
			</extension>
		</complexContent>
	</complexType>
The error (it seems) therefore has a problem with how I've used the gml:Point element, however I have used it as per the book I have on gml and it seemingly should work according to the above definition. Though their schema is somewhat more complex that I am comfortable reading!

Hopefully someone can pinpoint my error - it's probably a simple one knowing me! Thanks

Last edited by jamesdurham; April 7th, 2009 at 07:04 PM.. Reason: tidied up some code
 
Old April 7th, 2009, 07:03 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xs:element ref="gml:Point">
<xs:complexType>

When you use ref= on an element particle, it means the element and its type are declared elsewhere (globally). So it doesn't make sense to define its type locally in a nested complexType element.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 7th, 2009, 07:13 PM
Authorized User
 
Join Date: Mar 2009
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

oooooo! I think I see what you mean.

It now works if I cut it down to:
Code:
<xs:element name="location" minOccurs="0" maxOccurs="1">
   <xs:complexType>
      <xs:sequence>
         <xs:element ref="gml:Point"/>
      </xs:sequence>
   </xs:complexType>
</xs:element>
and obviously I then had to trim the xml file to match the exact schema definition, so that became:
Code:
                <geo:location>
                    <gml:Point gml:id="slopePeak">
                        <gml:pos>316865 504940</gml:pos>
                    </gml:Point>
                </geo:location>
My problem now is that I will either have to relocate the other elements (that were from my namespace) that were located as children of gml:Point (and hence change several XSLT files, which could be a pain), or is there a way I could add to the GML schema or my schema to allow for the inclusion of geo:lat and geo:long as siblings to gml:pos (hence children of gml:Point)?
(That would be best if possible.)

edit: I have one other case for which I will need to somehow edit the schema of another xml application (diggs) whilst maintaining its integrity. In that case I really cannot move the elements to another location due to logic etc. Therefore if someone knows of a general method I could adopt for achieving this then that would be greatly appreciated. i.e. adding one or two more attributes as descendants of elements defined in another xml application.

My guess would be to import or include the relevant schemas in to a new schema file, then copy across the relevant element and then add in the couple of elements from my namespace that I wish to be held within. My quick go at it though seems to have failed. I'll perhaps wait and see if this is the correct way to go. I'm guessing there is probably something simpler or perhaps a direct way of achieving it other than what I previously attempted a few posts up (the one which caused the errors).

Last edited by jamesdurham; April 7th, 2009 at 07:36 PM..




Similar Threads
Thread Thread Starter Forum Replies Last Post
BasePage and Namespace Issue Eric S. Smith BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 May 28th, 2008 08:43 AM
XML to XSD gagsy Pro Java 0 March 3rd, 2008 02:38 AM
namespace issue 2BOrNot2B XSLT 1 March 9th, 2007 05:32 PM
XML To XML, using XSL & XSD supercop75 XSLT 1 April 8th, 2006 02:48 AM
Converting xsd to xml lxu XML 0 June 4th, 2004 12:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.