Limit the value of an element based on existing XML data
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 9
- Joined: Wed Apr 11, 2018 4:43 pm
Limit the value of an element based on existing XML data
Post by daddyjones »
I'm fairly sure what I want to do can't be done, but I thought I'd ask on here just in case.
If I have the following XML:
Is it possible, in XML Schema to restrict a new element to the existing values of the name attribute? For example, I would define a new element called <foobar> which had an attribute called "name" and the value of the attribute could only be, in this case, lorem, ipsum, dolor or sit - and that's based on the XML and not an <xs:enumeration />. So if I added elements to the XML I would increase the possible values allowed.
I hope that all makes sense!
If I have the following XML:
Code: Select all
<foo>
<bar name="lorem" />
<bar name="ipsum" />
<bar name="dolor" />
<bar name="sit" />
...
</foo>
I hope that all makes sense!
-
- Posts: 388
- Joined: Thu Jul 01, 2004 12:29 pm
Re: Limit the value of an element based on existing XML data
Hello,
If you want to restrict the values from an attribute based on some exiting values from the XML, you can use Schematron rules inside XSD or as a separate Schematron schema file. The Schematron rule in your case can be something like this:
Best Regards.
Octavian
If you want to restrict the values from an attribute based on some exiting values from the XML, you can use Schematron rules inside XSD or as a separate Schematron schema file. The Schematron rule in your case can be something like this:
Code: Select all
<sch:rule context="foobar/@name">
<sch:let name="values" value="//bar/@name"/>
<sch:assert test=". = $values"> Invalid value "<sch:value-of select="."/>",
should be one of: "<sch:value-of select="$values"/>"
</sch:assert>
</sch:rule>
Best Regards.
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 9
- Joined: Wed Apr 11, 2018 4:43 pm
Re: Limit the value of an element based on existing XML data
Post by daddyjones »
thanks for the reply - so there's no way of doing this built into XML Schema itself? Would most standard parsers be able to validate based on both XML Schema and Schematron?
-
- Posts: 9
- Joined: Wed Apr 11, 2018 4:43 pm
Re: Limit the value of an element based on existing XML data
Post by daddyjones »
Could XPointer be used to achieve this?
-
- Posts: 9
- Joined: Wed Apr 11, 2018 4:43 pm
Re: Limit the value of an element based on existing XML data
Post by daddyjones »
Or XInclude? I think I could use XInclude to include an XML fragment - which might do, although I'm struggling to figure out how to get Oxygen to work with this...
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