0

I need an XSD that will mandate a specific top-level element exists in my XML data (first & last line), whilst allowing any XML data (sub-elements), as long as a specific element with a specific attribute exists anywhere in the data-set. Assuming this criteria is met, then the XML needs to be considered valid.

Example XMl Data Set

<Event>
<System>
  <Provider Name='LogRhythm Agent'/>
  <EventRecordID>88524</EventRecordID>
  <Channel>Application</Channel>
  <Computer>WIN-FFO09235PTC</Computer>
  <Security/>
</System>
<EventData>[NT AUTHORITY\SYSTEM] LogRhythm System Monitor Agent stopped</EventData>
</Event>

As you can see, the data-set is encapsulated within the Event element which i need to mandate, and within a sub-element is the computer element with a specific value WIN-FFO09235PTC, i need to mandate this exists while allowing any other XML data to exist within the Event element.

I tried this as my XSD

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" 
vc:minVersion="1.1">
  <xs:element name="Event">
    <xs:complexType>
      <xs:sequence>
        <xs:any minOccurs="0" maxOccurs="unbounded" 
processContents="lax"/>
      </xs:sequence>
      <xs:assert test="//Computer[@fixed='WIN-FFO09235PTC']"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

I'm looking for the XSD to validate against here - https://www.liquid-technologies.com/online-xsd-validator

However i get this error - 1:7 sample.xml cvc-elt.1.a: Cannot find the declaration of element 'Event'.

  • While asking an XSD question you need to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example): (1) Well-formed input XML. (2) Your logic, and XSD that tried to implement it. (3) XSD processor and its conformance with the XSD standards: 1.0, or 1.1. – Yitzhak Khabinsky May 30 '23 at 20:54
  • xsd.exe supports only XSD 1.0; `xs:assert` requires XSD 1.1. – kjhughes May 30 '23 at 20:58

0 Answers0