Let’s say I define the following XML schema, author.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="author">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</xml>
How would I go about just including the XML schema once when defining multiple author elements in my actual XML file? I would like to avoid having to define xmlns:xsi for every author element.
<?xml version="1.0"?>
<author xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="author.xsd">
<FirstName>Mark</FirstName>
<LastName>Twain</LastName>
</author>
<author xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="author.xsd">
<FirstName>Awesome</FirstName>
<LastName>Possum</LastName>
</author>
From what I understood, you want the xml file to have more than 1
author. If that is the case then you need to define a parent element and haveauthoras the child of it. Parent element acts like a container. So here is the rule of XMLAn xml file can have only 1 root element. All other elements should be children of it.
So, I’d change your schema like this
NOTE
If you want to limit authors to say 100 then change
maxOccursto that value.