XSD - how to determine the relationship between two elements

I have an XSD file as shown below:

<element name="finder-def" minOccurs="0" maxOccurs="unbounded">
    <complexType>
         <attribute name="name" type="string" use="required"></attribute>
         <attribute name="description" type="string"></attribute>
         <attribute name="class" type="string" use="required"></attribute>
    </complexType>
</element>

<complexType name="Dimension">
    <sequence>
        <element name="finder" type="Finder" minOccurs="0" maxOccurs="1"/>
    </sequence>
</complexType>

<complexType name="Finder">
    <attribute name="name" type="String" use="required"/>
</complexType> 

The XML file corresponds to the above XSD file below:

<finder-def name="circleFinder" description="Finds circle based on msisdn" class="com.onmobile.reporting.etl.processor.common.propertyplugins.CircleIdPropertyPlugin" />

<dimension name="circleId">
    <finder name="circleFinder" />
</dimension>

So, here I defined one finder-defie circleFinder, and then I want to access this element finder-defthrough finder.

So, the question is how to verify that it finder circleFinderhas its protection defined above infinder-def

+5
source share
1 answer

Another way to use the ID and IDREF types inside a schema. Example: XML Example:

<?xml version="1.0" encoding="UTF-8"?>
<f:root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:f="http://test.com/finder" xsi:schemaLocation="http://test.com/finder finder.xsd">

<f:finder-def name="circleFinder" description="Finds circle based on msisdn"
              class="com.onmobile.reporting.etl.processor.common.propertyplugins.CircleIdPropertyPlugin"/>

<f:dimension name="circleId">
    <f:finder name="circleFinder"/>
</f:dimension>
</f:root>

XSD scheme (I formatted it a bit for verification)

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://test.com/finder"
        xmlns:tns="http://test.com/finder"
        elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="root">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="finder-def" type="tns:finder-def" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="dimension" type="tns:Dimension" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>
<xsd:complexType name="finder-def">
    <xsd:attribute name="name" type="xsd:ID" use="required"/>
    <xsd:attribute name="description" type="xsd:string"/>
    <xsd:attribute name="class" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="Dimension">
    <xsd:sequence>
        <xsd:element name="finder" type="tns:Finder" minOccurs="0" maxOccurs="1"/>
    </xsd:sequence>
    <xsd:attribute name="name" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="Finder">
    <xsd:attribute name="name" type="xsd:IDREF" use="required"/>
</xsd:complexType>
</xsd:schema>
+2
source

All Articles