How to make geometry topology via XML and XSD?

116 views Asked by At

I need to find the way of defining lines using topology representation. Now i have something similar to it:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <Points>
        <Point>
            <UIDP>1</UIDP>
            <X>5379847.689</X>
            <Y>1223602.644</Y>
            <MX>0.05</MX>
            <MY>0.05</MY>
        </Point>
        <Point>
            <UIDP>2</UIDP>
            <X>5379828.473</X>
            <Y>1223606.113</Y>
            <MX>0.05</MX>
            <MY>0.05</MY>
        </Point>
    </Points>
    <Lines>
        <Line>
            <Point>1</Point>/>
            <Point>2</Point>/>
        </Line>
    </Lines>  
</Root>

Where Line/Point is the value of point unique id(UIDP).

Questions

  1. Is there any way to make it more clearly, get not only ID but hole point definition using references or something similar?
  2. How to make it using XLink or XPointer?
  3. How to define it in XSD Schema 1.1?
2

There are 2 answers

1
Roman Peresoliak On

I didn't find how to make it though XLink or XPointer but uderstand how to define part of rules via XSD.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">

    <xsd:complexType name="point">
        <xsd:sequence>
            <xsd:element name="UIDP" type="xsd:integer"/>
            <xsd:element name="X" type="xsd:float"/>
            <xsd:element name="Y" type="xsd:float"/>
            <xsd:element name="MX" type="xsd:float"/>
            <xsd:element name="MY" type="xsd:float"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="line">
        <xsd:sequence>
            <xsd:element name="Point1" type="xsd:integer"/>
            <xsd:element name="Point2" type="xsd:integer"/>
        </xsd:sequence>
        <xsd:assert test="Point1 != Point2"/>
    </xsd:complexType>

    <xsd:element name="Root">
        <xsd:complexType>
            <xsd:sequence>

                <xsd:element name="Points">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="Point" type="point" maxOccurs="unbounded"/>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>

                <xsd:element name="Lines">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="Line" type="line" maxOccurs="unbounded"/>      
                        </xsd:sequence>
                    </xsd:complexType>

                    <xsd:unique name="lines_unique">
                        <xsd:selector xpath="Line"/>
                        <xsd:field xpath="Point1"/>
                        <xsd:field xpath="Point2"/>
                    </xsd:unique>

                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>

        <xsd:key name="point_uidp">
            <xsd:selector xpath="Points/Point"></xsd:selector>
            <xsd:field xpath="UIDP"></xsd:field>
        </xsd:key>

        <xsd:keyref refer="point_uidp" name="point_1">
            <xsd:selector xpath="Lines/Line/Point1"></xsd:selector>
            <xsd:field xpath="."></xsd:field>
        </xsd:keyref>

        <xsd:keyref refer="point_uidp" name="point_2">
            <xsd:selector xpath="Lines/Line/Point2"></xsd:selector>
            <xsd:field xpath="."></xsd:field>
        </xsd:keyref>

    </xsd:element>

</xsd:schema>

Rules defined by schema:

  1. all of points id's have to be unique, must appear and cannot be NULL
  2. all line point links have to be from range of points id's
  3. line point links must be unique and cant be duplicated in other line
0
Alexander Petrov On

.NET DataSet class autogenerate following schema (I added blank lines for clarity):

<?xml version="1.0" standalone="yes"?>
<Root>
  <xs:schema id="Root" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
             xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

    <xs:element name="Root" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">

          <xs:element name="Point">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="UIDP" type="xs:int" />
                <xs:element name="X" type="xs:double" minOccurs="0" />
                <xs:element name="Y" type="xs:double" minOccurs="0" />
                <xs:element name="MX" type="xs:double" minOccurs="0" />
                <xs:element name="MY" type="xs:double" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>

          <xs:element name="Line">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="Point1" type="xs:int" />
                <xs:element name="Point2" type="xs:int" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>

        </xs:choice>
      </xs:complexType>

      <xs:unique name="PK_Points" msdata:PrimaryKey="true">
        <xs:selector xpath=".//Point" />
        <xs:field xpath="UIDP" />
      </xs:unique>

      <xs:unique name="PK_Lines" msdata:PrimaryKey="true">
        <xs:selector xpath=".//Line" />
        <xs:field xpath="Point1" />
        <xs:field xpath="Point2" />
      </xs:unique>

      <xs:keyref name="FK_Lines2" refer="PK_Points" msdata:ConstraintOnly="true">
        <xs:selector xpath=".//Line" />
        <xs:field xpath="Point2" />
      </xs:keyref>

      <xs:keyref name="FK_Lines1" refer="PK_Points" msdata:ConstraintOnly="true">
        <xs:selector xpath=".//Line" />
        <xs:field xpath="Point1" />
      </xs:keyref>

    </xs:element>
  </xs:schema>

  <Point>
    <UIDP>1</UIDP>
    <X>5379847.689</X>
    <Y>1223602.644</Y>
    <MX>0.05</MX>
    <MY>0.05</MY>
  </Point>
  <Point>
    <UIDP>2</UIDP>
    <X>5379828.473</X>
    <Y>1223606.113</Y>
    <MX>0.05</MX>
    <MY>0.05</MY>
  </Point>

  <Line>
    <Point1>1</Point1>
    <Point2>2</Point2>
  </Line>
</Root>

The scheme is generated in a single file along with the data.

Note the absence of Points and Lines elements.

Unfortunately is the schema of version 1.0. Therefore, more advanced checks is not available.

Attributes with the msdata prefix can be removed.