XML pattern unique child elements

I am trying to verify whether the parent element has a unique child element by element name.
I also need to verify that there is at least one possible element.

Example





It will work but






and

 

It will be invalid.

I have tried to use xs: unique to select the current node, but I cannot usually use the field element to select elements.

The following is mine What I want to do, but it is not the powerful solution I want. I want to be able to add more types instead of changing the xpath for each change.








< p>Is it possible? Is this a good habit? Any comments would be greatly appreciated.

It’s impossible to use a general solution based on XSD 1.0. I don’t Believe that your unique performance achieves what you want, just because you use text() to evaluate the value of a field; so the name of the tag will never be in this…

Although you may be able to reach you What you want, but it may not be suitable for all scenarios, or it lacks elegance or feasibility…

Some people may not think the following method is elegant…Nonetheless, it can Serves the same purpose.

For example, if you use attributes to capture the “tag” name, it looks like this:





< p>Then write your unique on the @type field, combined with a series of storage, maxOccurs = whatever will be given exactly as you describe.

If you are looking for elements that actually have complex content, Or attributes are not allowed, then you can use replacement groups to achieve the same effect.

I tried to verify whether the parent element has a unique child element by the element name.
I also need to verify that there is at least one possible element.

Example





It will work but






and

 

will be invalid.

I have tried to use xs: unique to select the current node, but I can’t usually use the field element to select elements.

Following Is what I want to do, but it is not the powerful solution I want. I want to be able to add more types instead of changing the xpath for each change.

 


< br />


Is this possible? Is this a good habit? Any comments would be greatly appreciated.

It is impossible to use a general solution based on XSD 1.0. I don’t believe your unique performance achieves what you want, just Because text() is used to evaluate the value of a field; so the name of the tag will never be in this…

Although you may be able to achieve what you want, it may not be suitable for all The scene, or it lacks elegance or feasibility…

Some people may not think the following method is elegant…Nonetheless, it can serve the same purpose.

For example, if you use attributes to capture the “tag” name, it looks like this:


< br />

Then write your unique on the @type field , And combined with a series of storage, maxOccurs = whatever will be given exactly as you describe.

If you are looking for elements that actually have complex content, or do not allow attributes, then you can use replacement groups to Achieve the same effect.

Leave a Comment

Your email address will not be published.