Validation XML against XSD

This should cover W3C XML Schema, Relax NG and DTD related problems.
Hoppy02
Posts: 1
Joined: Sun Jun 02, 2019 2:21 am

Validation XML against XSD

Post by Hoppy02 »

Hi all, i am trying to validate my xml against a xsd, but unfortunately i am getting following error:

11:44 schema.xsd src-resolve.4.1: Error resolving component 'gYear'. It was detected that 'gYear' has no namespace, but components with no target namespace are not referenceable from schema document 'virtual://server/schema.xsd'. If 'gYear' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'gYear' has no namespace, then an 'import' without a "namespace" attribute should be added to 'virtual://server/schema.xsd'.
11:44 schema.xsd src-resolve: Cannot resolve the name 'gYear' to a(n) 'type definition' component.

what am I doing wrong? :?

XML

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<gml:FeatureCollection gml:id="Trinkwaser_NRW.xml" xsi:schemaLocation="http://www.bafg.de/namespace/dwd/2009 Schema.xsd http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/base/gml.xsd" xmlns:dwd="http://www.bafg.de/namespace/dwd/2009" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<gml:featureMember>
		<dwd:GeneralInformation gml:id="GeneralInformation_1">
			<dwd:ReportType>DWD_1000</dwd:ReportType>
			<dwd:CountryStateCode>Nordrhein-Westfalen</dwd:CountryStateCode>
			<dwd:Year>2013</dwd:Year>
			<dwd:TotalPopulation>3.4</dwd:TotalPopulation>
			<dwd:NumberWSZ>56</dwd:NumberWSZ>
			<dwd:Groundwater>90</dwd:Groundwater>
			<dwd:Surfacewater>5</dwd:Surfacewater>
			<dwd:Inlandwater>5</dwd:Inlandwater>
			<dwd:Coastalwater>0</dwd:Coastalwater>
			<dwd:Bankfiltrationwater>3</dwd:Bankfiltrationwater>
			<dwd:ArtificialGrondwaterRecharge>0</dwd:ArtificialGrondwaterRecharge>
			<dwd:Rainwater>2</dwd:Rainwater>
			<dwd:Otherwater>0</dwd:Otherwater>
			<dwd:WebsiteAddress>http://www.trinkwasser_nrw.de</dwd:WebsiteAddress>
			<dwd:ResponsibleAuthority>Landesgesundheitsamt NRW</dwd:ResponsibleAuthority>
			<dwd:Name>Herr Mustermann</dwd:Name>
			<dwd:Address>Musterstraße 1</dwd:Address>
			<dwd:City>12345 Musterstadt</dwd:City>
			<dwd:Telephone>123456</dwd:Telephone>
			<dwd:Fax>654321</dwd:Fax>
			<dwd:Email>max.mustermann@musterstadt.de</dwd:Email>
			<dwd:NoAnnualMonitoringReport>true</dwd:NoAnnualMonitoringReport>
		</dwd:GeneralInformation>
	</gml:featureMember>
</gml:FeatureCollection>
XSD

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dwd="http://www.bafg.de/namespace/dwd/2009" xmlns:gml="http://www.opengis.net/gml" targetNamespace="http://www.bafg.de/namespace/dwd/2009" elementFormDefault="qualified" version="0.4">
	<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"/>
	<xsd:element name="GeneralInformation" type="dwd:GeneralInformationType" substitutionGroup="gml:_Feature"/>
	<xsd:complexType name="GeneralInformationType">
		<xsd:complexContent>
			<xsd:extension base="gml:AbstractFeatureType">
				<xsd:sequence>
					<xsd:element name="ReportType" type="gml:CodeType"/>
					<xsd:element name="CountryStateCode" type="gml:CodeType"/>
					<xsd:element name="Year" type="gYear"/>
					<xsd:element name="TotalPopulation" type="double"/>
					<xsd:element name="NumberWSZ" type="integer"/>
					<xsd:element name="Groundwater" type="double"/>
					<xsd:element name="Surfacewater" type="double"/>
					<xsd:element name="Inlandwater" type="double"/>
					<xsd:element name="Coastalwater" type="double"/>
					<xsd:element name="Bankfiltrationwater" type="double"/>
					<xsd:element name="ArtificialGrondwaterRecharge" type="double"/>
					<xsd:element name="Rainwater" type="double"/>
					<xsd:element name="Otherwater" type="double"/>
					<xsd:element name="WebsiteAddress" type="anyURI" maxOccurs="unbounded"/>
					<xsd:element name="ResponsibleAuthority" type="string"/>
					<xsd:element name="Name" type="string"/>
					<xsd:element name="Address" type="string"/>
					<xsd:element name="City" type="string" minOccurs="0"/>
					<xsd:element name="Telephone" type="string"/>
					<xsd:element name="Fax" type="string"/>
					<xsd:element name="Email" type="string"/>
					<xsd:element name="NoAnnualMonitoringReport" type="boolean"/>
				</xsd:sequence>
			</xsd:extension>
		</xsd:complexContent>
	</xsd:complexType>
	<xsd:complexType name="GeneralInformationPropertyType">
		<xsd:sequence minOccurs="0">
			<xsd:element ref="dwd:GeneralInformation"/>
		</xsd:sequence>
		<xsd:attributeGroup ref="gml:AssociationAttributeGroup"/>
	</xsd:complexType>
</xsd:schema>
tavy
Posts: 364
Joined: Thu Jul 01, 2004 12:29 pm

Re: Validation XML against XSD

Post by tavy »

Hello,

In your schema you are using built-in types defined in the XML Schema, such as: gYear, integer, double. All the build-in types define in the XML Schema have the namespace "http://www.w3.org/2001/XMLSchema". Therefore, in order to refer the built-in types in you schema you must specify the prefix. In your case you already added the namespace declaration in your schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" , so you need to add the "xsd" prefix, something like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:dwd="http://www.bafg.de/namespace/dwd/2009" xmlns:gml="http://www.opengis.net/gml" targetNamespace="http://www.bafg.de/namespace/dwd/2009" elementFormDefault="qualified" version="0.4">
    <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"/>
    <xsd:element name="GeneralInformation" type="dwd:GeneralInformationType" substitutionGroup="gml:_Feature"/>
    <xsd:complexType name="GeneralInformationType">
        <xsd:complexContent>
            <xsd:extension base="gml:AbstractFeatureType">
                <xsd:sequence>
                    <xsd:element name="ReportType" type="gml:CodeType"/>
                    <xsd:element name="CountryStateCode" type="gml:CodeType"/>
                    <xsd:element name="Year" type="xsd:gYear"/>
                    <xsd:element name="TotalPopulation" type="xsd:double"/>
                    <xsd:element name="NumberWSZ" type="xsd:integer"/>
                    <xsd:element name="Groundwater" type="xsd:double"/>
                    <xsd:element name="Surfacewater" type="xsd:double"/>
                    <xsd:element name="Inlandwater" type="xsd:double"/>
                    <xsd:element name="Coastalwater" type="xsd:double"/>
                    <xsd:element name="Bankfiltrationwater" type="xsd:double"/>
                    <xsd:element name="ArtificialGrondwaterRecharge" type="xsd:double"/>
                    <xsd:element name="Rainwater" type="xsd:double"/>
                    <xsd:element name="Otherwater" type="xsd:double"/>
                    <xsd:element name="WebsiteAddress" type="xsd:anyURI" maxOccurs="unbounded"/>
                    <xsd:element name="ResponsibleAuthority" type="xsd:string"/>
                    <xsd:element name="Name" type="xsd:string"/>
                    <xsd:element name="Address" type="xsd:string"/>
                    <xsd:element name="City" type="xsd:string" minOccurs="0"/>
                    <xsd:element name="Telephone" type="xsd:string"/>
                    <xsd:element name="Fax" type="xsd:string"/>
                    <xsd:element name="Email" type="xsd:string"/>
                    <xsd:element name="NoAnnualMonitoringReport" type="xsd:boolean"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="GeneralInformationPropertyType">
        <xsd:sequence minOccurs="0">
            <xsd:element ref="dwd:GeneralInformation"/>
        </xsd:sequence>
        <xsd:attributeGroup ref="gml:AssociationAttributeGroup"/>
    </xsd:complexType>
</xsd:schema>
Best Regards.
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply