XML schema: how to allow one particular element anywhere?
Posted: Thu May 24, 2018 1:41 pm
I have a `xml` file that is basically the data of an article. I want to write a `xml schema` to validate that file. In the xml article's file, I have used a few tags in the middle of text, for instance:
I use that `em` tag elsewhere as well, inside other type of elements, so the problem isn't just to allow it inside `p`.
**My question:** how do I allow it to be used inside any elements of my schema?
I did not really understand those answers (I am a beginner), but it seems `openContent` might be the solution I am looking for.
Minimal Working Example:
Schema:
My real document involves some nested `sequence` and `choice`, and other documents I create will be different, so I am looking for a general solution.
**Optional question:**if the solution does not involve `openContent`, can someone explain me how it works as well? Search results were strangely lacking in example and explanations (for beginners), unlike everything I looked up.
Code: Select all
<p>The dog is <em>brown</em><p>
**My question:** how do I allow it to be used inside any elements of my schema?
I did not really understand those answers (I am a beginner), but it seems `openContent` might be the solution I am looking for.
Minimal Working Example:
Code: Select all
<?xml version="1.0"?>
<doc>
<foo>text <bar /> anything</foo>
<tag>text <bar /> </tag>
</doc>
Code: Select all
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="subclass">
<xs:complexType>
<xs:sequence>
<xs:element name="foo">
</xs:element>
<xs:element name="tag">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
**Optional question:**if the solution does not involve `openContent`, can someone explain me how it works as well? Search results were strangely lacking in example and explanations (for beginners), unlike everything I looked up.