Problem creating complex types when using XML data binding

I use XML data mapping and have a problem creating complex types when using it.

If I have XML, for example, below its working quality

<?xml version="1.0" standalone="yes" ?>
<Sample>
      <connection>
        <item  Name="ABC">123</item>
        <item  Name="XYZ">123</item>
        <item  Name="MNO">123</item>
      </connection>
      <connection>
        <item  Name="ABC">123</item>
        <item  Name="XYZ">123</item>
        <item  Name="MNO">123</item>
      </connection>
</Sample>

I get complex types like SampleType, ConnectionType and ItemType.

But if I have XML like

<?xml version="1.0" standalone="yes" ?>
<Sample>
      <connection>
        <item  Name="ABC"/>
        <item  Name="XYZ"/>
        <item  Name="MNO"/>
      </connection>
      <connection>
        <item  Name="ABC"/>
        <item  Name="XYZ"/>
        <item  Name="MNO"/>
      </connection>
</Sample>

I get complex types like SampleType, ConnectionType, ItemType, ItemType2, ItemType22, ItemType222, ItemType2222, and ItemType22222, i.e. ItemTypes were equal to the number of elements present in XML.

Why is this happening and how can I solve this problem?

+3
source share
1 answer

, XML ( XML- ), XML Schema.

XML- , XML.

XML- , , XSD DTD.

, , , XSD. XSD XML, XSD.

XML-2-XSD XSD, .

XSD , .

. XML -, , XML Delphi. , null XML, .

: XSD XML.

XmlForAsp, XSD, .

XSD XML- :

<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="Sample" type="SampleType" />
  <xsd:complexType name="SampleType">
    <xsd:sequence>
      <xsd:element maxOccurs="unbounded" name="connection" type="connectionType" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="connectionType">
    <xsd:sequence>
      <xsd:element maxOccurs="unbounded" name="item" type="itemType" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="itemType">
    <xsd:attribute name="Name" type="xsd:string" />
  </xsd:complexType>
</xsd:schema>

-

+2

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


All Articles