Valid xml and Schema

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Solstice
Posts: 1
Joined: Wed Mar 16, 2022 9:54 pm

Valid xml and Schema

Post by Solstice »

I need to verify xml is correct and I need help writing my XML Schema.

Code: Select all

<?xml version="1.0 encoding="UTF-8" standalone="yes">
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<0>
	<fname>John</fname>
	<lname>Doe</lname>
	<email>doejohn@gmail.com</email>
</0>
<1>
	<fname>Jane</fname>
	<lname>Doe</lname>
	<email>doejane@yahoo.com</email>
</1>
Radu
Posts: 9434
Joined: Fri Jul 09, 2004 5:18 pm

Re: Valid xml and Schema

Post by Radu »

Hi,
Something like this <0> is not a valid XML element name, a valid element name starts with a letter or underscore:
https://www.w3schools.com/xml/xml_elements.asp

Also you cannot build an XML schema to validate an XML document which may contain an arbitrary number of tag names, for example <0>, <1>....<1000>.
If your XML would look like this:

Code: Select all

<data-set>
    <person number="0">
        <fname>John</fname>
        <lname>Doe</lname>
        <email>doejohn@gmail.com</email>
    </person>
    <person number="1">
        <fname>Jane</fname>
        <lname>Doe</lname>
        <email>doejane@yahoo.com</email>
    </person>
</data-set>
an XML Schema for it would look like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="data-set">
        <xs:complexType>
           <xs:sequence>
               <xs:element name="person" maxOccurs="unbounded">
                   <xs:complexType>
                       <xs:sequence>
                           <xs:element name="fname" type="xs:string"/>
                           <xs:element name="lname" type="xs:string"/>
                           <xs:element name="email" type="xs:string"/>
                       </xs:sequence>
                       <xs:attribute name="number" type="xs:integer"/>
                   </xs:complexType>
               </xs:element>
           </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply