1

First, sorry for my English.

I want to know how to create a XSD from this XML without subtyping

<component>
  <id />
  <entry>
    <relation>
      <observation>
        <id />
      </observation>
    </relation>
  </entry>
</component>

<component>
  <id code="" />
  <entry>
    <observation status="" value="">
      <id />
    </observation>
  </entry>
</component>

As you see there are 2 elements named "component" with different structures but I can't modify the XML because I need an XSD for a standard XML for CDA (Clinical Document Architecture).

I can't add the "type" attribute to the "component" element and I can't use the same complex type structure for both "components". It must be separated.

SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • This is not a valid XML, first of all. As you mentioned you have to keep components separate then you need to create parent element to both of them. These two components inside the newly created parent element would have its own type. – Madhusudan Joshi Nov 24 '15 at 23:54
  • @Joshi: No, two sibling elements with the same name cannot have different types. Also, you mean [***well-formed***, not ***valid***](http://stackoverflow.com/a/25830482/290085). – kjhughes Nov 25 '15 at 00:23
  • XML is not valid because of `No Root element`. And two similar elements with diff types should not be directly inside root. This is one of the suggested approach. – Madhusudan Joshi Nov 25 '15 at 00:28
  • You can take the updated xml data and validate in any xml validator tool, it will validate, i think. I do not need to read about well formed and valid, as i was not wrong. Thank you. – Madhusudan Joshi Nov 25 '15 at 00:35

1 Answers1

0

In XSD, an element such as component can be defined locally differently depending upon its context. (Note, however, that same-named siblings cannot have different types.) An element cannot be defined globally differently without using separate XSDs and separate namespaces.

XSD 1.1 affords some additional options: You might use Condition Type Assignment (example here) to have type depend upon a attribute value, or you might restrict otherwise optional components depending upon a condition specified in an assertion.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240