Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

XSD: Nested XML with a choice on the root element

Posted on 2004-10-21
1
Medium Priority
?
358 Views
Last Modified: 2013-11-19
I've got a pair of XML's that I would to validate with one XSD:

<TestCase name="TC1">
     ...
</TestCase>

<TestSuite name="TS1">
     <TestCase name="TC1">
          ...
     </TestCase>
     <TestSuite name="TS2">
          <TestCase name="TC2">
               ...
          </TestCase>
     </TestSuite>
</TestSuite>

A TestSuite can simply contain 0 or more TestCases and TestSuites (in any order).

Is it possible (or advisable) to validate both the TestCase xml and the TestSuite xml with the same xsd?
0
Comment
Question by:forloop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 26

Accepted Solution

by:
rdcpro earned 200 total points
ID: 12374877
Sure, you can do this.

<?xml version="1.0" encoding="UTF-8"?>
<TestCase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="F:\msharp\Pro Bono\schematest\test.xsd" name="TC3">
      <foo>Tarfu</foo>
</TestCase>


and

<TestSuite name="TS1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="F:\msharp\Pro Bono\schematest\test.xsd">
      <TestCase name="TC1"><foo>bar</foo></TestCase>
      <TestSuite name="TS2">
            <TestCase name="TC2"><foo>snafu</foo></TestCase>
      </TestSuite>
</TestSuite>

both validate against:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
      <xs:complexType name="TestCaseType">
            <xs:sequence>
                  <xs:element name="foo" type="xs:string" />
            </xs:sequence>
            <xs:attribute name="name" use="required" type="xs:NMTOKEN"/>
      </xs:complexType>
      <xs:complexType name="TestSuiteType">
            <xs:sequence>
                  <xs:element name="TestCase" type="TestCaseType"/>
                  <xs:element name="TestSuite" type="TestSuiteType" minOccurs="0" maxOccurs="1"/>
            </xs:sequence>
            <xs:attribute name="name" use="required" type="xs:NMTOKEN"/>
      </xs:complexType>
      <xs:element name="TestCase" type="TestCaseType"/>
      <xs:element name="TestSuite" type="TestSuiteType"/>
</xs:schema>


Regards,
Mike Sharp
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question