Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 68439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:25:00+00:00 2026-05-10T19:25:00+00:00

The XML I’m trying to validate is as follows: <root> <element attribute=foo> <bar/> </element>

  • 0

The XML I’m trying to validate is as follows:

<root>     <element attribute='foo'>         <bar/>     </element>     <element attribute='hello'>         <world/>     </element> </root> 

How can this be validated using a Schema?

Note:

element can only contain bar when attribute=’foo’.

element can only contain world when attribute=’hello’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:25:00+00:00Added an answer on May 10, 2026 at 7:25 pm

    You can’t do this in XML Schema 1.0. In XML Schema 1.1 you will be able to use the <xs:assert> element to do it, but I’m guessing you want something that you can use now.

    You can use Schematron as a second layer of validation that will allow you to test arbitrary XPath assertions about your XML document. There’s a fairly old article about embedding Schematron in XSD that you might find helpful.

    You’d do something like:

    <rule context='element'>   <report test='@attribute = 'foo' and *[not(self::bar)]'>     This element's attribute is 'foo' but it holds an element that isn't a bar.   </report>   <report test='@attribute = 'hello' and *[not(self::world)]'>     This element's attribute is 'hello' but it holds an element that isn't a world.   </report> </rule> 

    Or of course you can switch to RELAX NG, which does this in its sleep:

    <element name='element'>   <choice>     <group>       <attribute name='attribute'><value>foo</value></attribute>       <element name='bar'><empty /></element>     </group>     <group>       <attribute name='attribute'><value>hello</value></attribute>       <element name='world'><empty /></element>     </group>   </choice> </element> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

xml: <root> <element>value (something)</element> </root> I need to unmarshall this xml to two different
XML: <Root> <Elements> <Element>el1</Element> <Element>el2</Element> </Elements> <Elements> <Element>el1</Element> <Element>el2</Element> </Elements> </Root> Trying to generate
An XML attribute declared as xs:boolean can acceptable be true, false, 0 or 1.
XML snippet: <AA> <BB>foo</BB> <CC>bar</CC> <DD>baz</DD> <EE>bar</EE> </AA> How do I select all the
XML confuses me sometimes, but I'm trying to get this figured out. What the
xml.etree.ElementTree.parse is choking on my xhtml file. I saw somewhere that lxml can handle
This XML file contained archived news stories for all of last year. I was
Which XML validation tools can you recommend for both performance and accuracy, each of
Can XML be used for displaying an animated image in my android layout?
My XML file looks like this: <Messages> <Contact Name=Robin Number=8775454554> <Message Date=24 Jan 2012

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.