1

I'm trying to write a xsd to validate the input files for my program.

Maybe it's me, but for this case it seems odd to me, that I need to define all the elements, which might appear in the xml, as I just need a subset of the contained data and the xml might be extended in the future. Given this is my xml:

    <?xml version="1.0" encoding="utf-8"?>
      <Setup>
         <Foo desc="i don't need you">This is some random Element</Foo>
         <Bar>This is what i need to process</Bar>
         <Bar>And it might appear more than once</Bar>
         <Foobar>Some other random element. There might be more</Foobar>
      </Setup>

Is there a xsd that is valid as long as <Setup>-><Bar> is present, no matter if there are random other elements present anywhere under <Setup>?

I think the basic structure might be something like

<?xml version="1.0" encoding="utf-8"?>
   <xs:schema>
      <xs:element name="Setup">
         <xs:complexType>
           <xs:someting>
              <xs:element name="bar" type="xs:string" minOccurence="1" maxOccurence="unbounded"/>
              <xsd:any  processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
            </xs:something>
         </xs:complexType>
      </xs:element>
   </xs:schema>

But <any> just seems to allow appending elements, and I haven't found a solution with <choice>, <sequence> or <all> or a combination of these to work around this. Is there some trick to do it?

P.S.: XSD1.1 sadly is not an option

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
Kevin Gebhardt
  • 368
  • 1
  • 12
  • Can you change the requirement that the `` element must be the first child of ``? – Progman Nov 08 '19 at 18:44
  • 1
    According to https://stackoverflow.com/questions/32741978/xsd-allow-any-unknown-element-in-any-order and https://stackoverflow.com/questions/37486498/xsdany-other-elements-inside-choice it might not be possible without using XSD1.1 – Progman Nov 08 '19 at 18:53
  • @ Progman: No, the xml is not under my control. It seems, the best way for now is to include the first level elements and just hope, that they won't change... – Kevin Gebhardt Nov 11 '19 at 14:27

0 Answers0