XML – We can make elements into optional elements or mandatory elements based on any other elements in XSD

In XSD, I have an element x with value (a,b)

There is another element y

Yes There is no way to use XSD, so that I can make y mandatory when the value of x is b, and optional if the value of x is a.

< /div>

Take a look at XML Schema Part 0: Primer Second Edition, Section 2.2.1 Occurrence Constraints.

It says:

In general, an element is required to appear when the value of minOccurs is 1 or more. The maximum number of times an element may appear is determined by the value of a maxOccurs attribute in its declaration . This value may be a positive integer such as 41, or the term unbounded to indicate there is no maximum number of occurrences. The default value for both the minOccurs and the maxOccurs attributes is 1.

Since the attribute value cannot be inferred from other schema content in XML Schema, you cannot achieve it (using XML Schema).

(I don’t know if Relax NG can do this, but you can investigate whether it Support this kind of content-dependent definition.)

In XSD, I have an element x with value (a,b)

There is another element y

Is there a way to use XSD so that I can make y mandatory when the value of x is b, and optional if the value of x is a.

< /p>

Look at XML Schema Part 0: P rimer Second Edition, section 2.2.1 Occurrence Constraints.

It says:

In general, an element is required to appear when the value of minOccurs is 1 or more. The maximum number of times an element may appear is determined by the value of a maxOccurs attribute in its declaration. This value may be a positive integer such as 41, or the term unbounded to indicate there is no maximum number of occurrences. The default value for both the minOccurs and the maxOccurs attributes is 1.

Because the attribute values ​​cannot be inferred from other schema contents in XML Schema, you Not possible (using XML Schema).

(I don’t know if Relax NG can do this, but you can investigate whether it supports this content-dependent definition.)

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 6015 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.