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'.