XML Schma - Addiing optional fields
This should cover W3C XML Schema, Relax NG and DTD related problems.
XML Schma - Addiing optional fields
I have the following XML
<request>
<system>ABC</system>
<id>XYZ123</id>
<dynamic>
<serial>
<id>X123456</id>
<id>A123456</id>
</serial>
<pool>
<id>y123456</id>
<id>d123456</id>
</pool>
</dynamic>
</request>
Now I need to conver the xml to XSD with the following business rule
<dynamic> element is optional field
if the <dynamic> field is defined it should have either one of these fields or both <serial> & <pool>
if <serial> or <pool> is defined it should have atleast one element <id>
I'm not sure how to convert the above xml to XSD and I tried couple of conversion tool and they do not have the options...
any help is appreciated.
<request>
<system>ABC</system>
<id>XYZ123</id>
<dynamic>
<serial>
<id>X123456</id>
<id>A123456</id>
</serial>
<pool>
<id>y123456</id>
<id>d123456</id>
</pool>
</dynamic>
</request>
Now I need to conver the xml to XSD with the following business rule
<dynamic> element is optional field
if the <dynamic> field is defined it should have either one of these fields or both <serial> & <pool>
if <serial> or <pool> is defined it should have atleast one element <id>
I'm not sure how to convert the above xml to XSD and I tried couple of conversion tool and they do not have the options...
any help is appreciated.
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
Hello,
You can use the Convert to action from the toolbar to convert your XML instance to XML Schema and then edit the result and add the restrictions that you want:
- The reference to dynamic has the attribute minOccurs="0"
- The definition of dynamic contains a choice element that means serial or pool or serial and pool
- The definitions of serial and pool contain a reference to attribute id with the attribute maxOccurs="unbounded"
Best regards,
Sorin
You can use the Convert to action from the toolbar to convert your XML instance to XML Schema and then edit the result and add the restrictions that you want:
- The reference to dynamic has the attribute minOccurs="0"
- The definition of dynamic contains a choice element that means serial or pool or serial and pool
- The definitions of serial and pool contain a reference to attribute id with the attribute maxOccurs="unbounded"
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="request">
<xs:complexType>
<xs:sequence>
<xs:element ref="system"/>
<xs:element ref="id"/>
<xs:element ref="dynamic" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="system" type="xs:NCName"/>
<xs:element name="dynamic">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:sequence>
<xs:element ref="serial"/>
<xs:element ref="pool" minOccurs="0"/>
</xs:sequence>
<xs:element ref="pool"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="serial">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="id"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="pool">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="id"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="id" type="xs:NCName"/>
</xs:schema>
Sorin
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