XML Schema
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 3
- Joined: Fri Sep 18, 2015 8:06 pm
XML Schema
Hello there
I have the following .xml code and the corresponding .xsd:
XML file:
XSD file:
Now I would like to extend the .xml file as following:
Extended XML file:
Evidently I have to add some lines to the .xsd file too.
I tried this:
My Problem: How do I set up the new .xsd properly if I insist on remaining the structure as shown in the first .xsd?
Thank you for your help!
Kind regards,
Troix
I have the following .xml code and the corresponding .xsd:
XML file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<lecturelist>
xmlns="http://www.my-fh.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.my-fh.com
file:lecturelist1.xsd">
<lecture>
<name>maths</name>
<semsester>1</semester>
</lecture>
</lecturelist>
XSD file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.my-fh.com"
xmlns:fh="http://www.my-fh.com"
>
<xs:element name="lecturelist">
<xs:complexType>
<xs:sequence>
<xs:element ref="fh:lecture" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="lecture">
<xs:complexType>
<xs:sequence>
<xs:element ref:"fh:name" />
<xs:element ref:"fh:semester" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:element name="semester" type="xs:string"/>
Extended XML file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<lecturelist>
xmlns="http://www.my-fh.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.my-fh.com
file:lecturelist1.xsd">
<lecture>
<name>maths</name>
<semester>1</semester>
</lecture>
<teacher>
<name>steinberg</name>
<age>55</age>
</teacher>
</lecturelist>
I tried this:
Code: Select all
]<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.my-fh.com"
xmlns:fh="http://www.my-fh.com"
xmlns:fb="http://www.my-fb.com"
>
<xs:element name="lecturelist">
<xs:complexType>
<xs:sequence>
<xs:element ref="fh:lecture" maxOccurs="unbounded" />
<xs:element ref="fb:teacher" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="lecture">
<xs:complexType>
<xs:sequence>
<xs:element ref:"fh:name" />
<xs:element ref:"fh:semester" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="teacher">
<xs:complexType>
<xs:sequence>
<xs:element ref:"fb:name" />
<xs:element ref:"fb:age" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:element name="semester" type="xs:string"/>
Thank you for your help!

Kind regards,
Troix
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XML Schema
Hi,
Stick to the same namespace (the schema target namespace) when working with a single XSD.
Stick to the same namespace (the schema target namespace) when working with a single XSD.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.my-fh.com"
xmlns:fh="http://www.my-fh.com">
<xs:element name="lecturelist">
<xs:complexType>
<xs:sequence>
<xs:element ref="fh:lecture" maxOccurs="unbounded" />
<xs:element ref="fh:teacher" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="lecture">
<xs:complexType>
<xs:sequence>
<xs:element ref="fh:name" />
<xs:element ref="fh:semester" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="teacher">
<xs:complexType>
<xs:sequence>
<xs:element ref="fh:name" />
<xs:element ref="fh:age" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:element name="semester" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="age" type="xs:string"/>
</xs:schema>
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 3
- Joined: Fri Sep 18, 2015 8:06 pm
Re: XML Schema
Hello adrian
Thank you for the reply.
So there is a "name" in "lecture" and "teacher".
If I were to say that the "name" in "lecture" is different to the "name" of "teacher" in terms of type how would I have to separate
them?
Thank you in advance,
Troix
Thank you for the reply.
So there is a "name" in "lecture" and "teacher".
If I were to say that the "name" in "lecture" is different to the "name" of "teacher" in terms of type how would I have to separate
them?
Thank you in advance,

Troix
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XML Schema
You can't declare two elements of the same name globally, so just declare the elements (or just one of them) locally (where used).If I were to say that the "name" in "lecture" is different to the "name" of "teacher" in terms of type how would I have to separate
them?
Code: Select all
<xs:element name="teacher">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element ref="fh:age" />
</xs:sequence>
</xs:complexType>
</xs:element>
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XML Schema
There's one other aspect that I forgot to mention. If you go with the local elements, you will also need to specify elementFormDefault="qualified" on the schema root, so that the local elements are placed in the target namespace. Otherwise, by default (unqualified), the local elements are in "no namespace".
Regards,
Adrian
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service