0

I have i.e. this XML:

<?xml version="1.0" encoding="UTF-8" ?>
<individual>
    <name>Baeldung</name>
    <address>
        <zip>00001</zip>
        <city>New York</city>
    </address>
</individual>

and would validate, wether it matches this schema:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="individual">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="name" type="xs:string" />
                <xs:element name="address">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="zip" type="xs:positiveInteger" />
                            <xs:element name="city" type="xs:string" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Is it any Swift technic to do it?

I looked at Apple XMLDocument library, but it does DTD validation. I think this is something else: https://developer.apple.com/documentation/foundation/xmldocument

Found this online tool, but it is not Swift: https://www.liquid-technologies.com/online-xsd-validator

  • If you look at the [validate](https://developer.apple.com/documentation/foundation/xmldocument/1408561-validate) method documentation you’ll see it can use an XML Schema for validation – Joakim Danielson Sep 14 '22 at 06:11
  • Does it mean I have to modify `` tag and put in an attribute like: `xsi:schemaLocation="https:/.."` which points the second xml? –  Sep 14 '22 at 06:33
  • 1
    Yes something like that, have a look at [this question](https://stackoverflow.com/questions/35411871/how-to-link-xml-to-xsd-using-schemalocation-or-nonamespaceschemalocation). – Joakim Danielson Sep 14 '22 at 06:52

0 Answers0