How to reference georss correctly: specify in my xsd?

I am compiling an XSD schema to describe an existing GeoRSS feed, but I am trying to use external georss.xsd to check for an element of type georss:point . I reduced the problem to the smallest components:

XML:

 <?xml version="1.0" encoding="utf-8"?> <this> <apoint>45.256 -71.92</apoint> </this> 

XSD:

 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:georss="http://www.georss.org/georss"> <xs:import namespace="http://www.georss.org/georss" schemaLocation="http://georss.org/xml/1.1/georss.xsd"/> <xs:element name="this"> <xs:complexType> <xs:sequence> <xs:element name="apoint" type="georss:point"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> 

If I make an apoint of type "xs: string" instead of "georss: point", XML successfully settles against XSD, but as soon as I refer to the imported type (georss: point), my XML validator (Notepad ++ | XML Tools) " impossible to parse the circuit. " What am I doing wrong?

+4
source share
2 answers

In the context of the question, you referred to a nonexistent type. Below you are working with:

enter image description here

If you need a point element, you reference it (as after). If you want to reuse a type (content model) using your own tag, then your apoint type must be doubleList .

Often reusing a type is a way to maximize the "lockout" of unwanted XML namespaces from an XML instance (see Venetian Blind author style ). In your case, you would get XML without a namespace.

+1
source

The final working example of solving what I was trying to achieve was as follows:

XML:

 <rss xmlns:georss="http://www.georss.org/georss"> <georss:point>-41.295781753436 173.229502017379</georss:point> </rss> 

XSD:

 <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:georss="http://www.georss.org/georss"> <xs:import namespace="http://www.georss.org/georss" schemaLocation="georss.xsd"/> <xs:element name="rss"> <xs:complexType> <xs:sequence> <xs:element ref="georss:point"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> 

The key is to use the ref attribute to refer to the type being imported.

 <xs:element ref="georss:point"/> 
0
source

Source: https://habr.com/ru/post/1438322/


All Articles