partial schema included in multiple subschemas - include

My aim is to make a modular XML schema that has some shared types in one file available to all subschema files. What's the best way to go around this?
Example:
Say I want to build an XML schema which describes XML documents about cars and bikes. I then create a schema for the XML, which I divide up into 4 files: vehicles.xsd, cars.xsd, bikes.xsd and types.xsd. vehicles.xsd includes cars.xsd and bikes.xsd and they both in turn include types.xsd. I noticed when trying out this example with the command
xmllint --schema vehicles.xsd vehicles.xml
that it validates fine, even though I was expecting a conflict to arise because of the double inclusion of types.xsd (which leads to 2 definitions of the complexType vehicleType). Removing the <include> tag from either cars.xsd or bikes.xsd also validates just fine. Can someone explain to me what is going on here?
XML and XSDs:
vehicles.xml:
<vehicles xmlns="http://example.com/vehicles">
<cars>
<car make="Porsche" model="911" />
<car make="Porsche" model="911" />
</cars>
<bikes>
<bike make="Harley-Davidson" model="WL" />
<bike make="Yamaha" model="XS650" />
</bikes>
</vehicles>
vehicles.xsd:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vh="http://example.com/vehicles"
targetNamespace="http://example.com/vehicles"
elementFormDefault="qualified">
<xs:include schemaLocation="cars.xsd" />
<xs:include schemaLocation="bikes.xsd" />
<xs:element name="vehicles">
<xs:complexType>
<xs:sequence>
<xs:element ref="vh:cars" />
<xs:element ref="vh:bikes" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
cars.xsd:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vh="http://example.com/vehicles"
targetNamespace="http://example.com/vehicles"
elementFormDefault="qualified">
<xs:include schemaLocation="types.xsd" />
<xs:element name="cars">
<xs:complexType>
<xs:sequence>
<xs:element name="car" type="vh:vehicleType"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
bikes.xsd:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vh="http://example.com/vehicles"
targetNamespace="http://example.com/vehicles"
elementFormDefault="qualified">
<xs:include schemaLocation="types.xsd" />
<xs:element name="bikes">
<xs:complexType>
<xs:sequence>
<xs:element name="bike" type="vh:vehicleType"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
types.xsd
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.com/vehicles">
<xs:complexType name="vehicleType">
<xs:attribute name="make" type="xs:string" />
<xs:attribute name="model" type="xs:string" />
</xs:complexType>
</xs:schema>

Most XSD processors notice, when asked to include a schema document like types.xsd, when they have already included it, and they avoid including it a second time; the XSD spec explicitly encourages this. That is why you are not getting error messages over the double inclusion, and why a single inclusion works fine for the merged case.
In general, however, there is slightly better interoperability among XSD processors if you keep things simpler by doing all inclusions from a single top-level driver file. If you used that idiom, you'd drop the xs:include elements from all your schema documents, and make one or more new driver documents which contain nothing but inclusions (one if you only want one schema; multiple driver documents if you want different schemas with different sets of elements).
Similar considerations apply to the use of the schemaLocation attribute on xs:import elements. The use of this idiom helps avoid situations (especially situations involving redefinition and reference cycles) which produce dramatically different results from different processors.

From the W3C specs for XML schema, i believe it was the intention to be able to have modular schemas and that can be included them where required. The preprocessor for the xml processor should resolve all includes and "import"s first.
I do have a extensive schema, that are broken up into small modular pieces. This works well on many xlm processors , and xml editors.

Related

BizTalk Mapping Fields to a Sequence

I am getting my hands on BizTalk and VS. My input schema looks something similar to this.
<root>
<order>
<orderid>
<orderdate>
...
...
and the output schema
<order>
<header:sequence>
<element name="orderid">
<element name="orderdate">
...
...
</header:sequence>
In short, in output, the header is a sequence of complex types and individual nodes in the source are enumerated as the sequence in the output.
How do we solve this in Visual Studio?
What you need to do is having a looping functoid that goes from each of the element being mapped and to the repeating destination element. And then two links from the source elements the first that is a standard link Copy text value, the second that goes to the name attribute, for which you change the link to Copy name.
Input
<root>
<order>
<orderid>1234567890</orderid>
<orderdate>2020-01-28</orderdate>
</order>
</root>
Output
<order>
<header>
<element name="orderid">1234567890</element>
<element name="orderdate">2020-01-28</element>
</header>
</order>
Note: You can change the order of what is output by using the reorder inputs in the Configure Looping Functoid.

Not equal xPath query limitations

I need to find logs from EventViewer in Forwarded Events based on computer name, excluding the ones which aren't interesting for me.
My query is like that
*[(System[(Computer!='comp1')]) and
(System[(Computer!='comp2')]) and
(System[(Computer!='comp3')]) and
(System[(Computer!='comp4')]) and
(System[(Computer!='comp5')]) and
(System[(Computer!='comp6')]) and
(System[(Computer!='comp7')]) and
(System[(Computer!='comp8')]) and
(System[(Computer!='comp9')]) and
(System[(Computer!='comp10')]) and
(System[(Computer!='comp11')]) and
(System[(Computer!='comp12')]) and
(System[(Computer!='comp13')]) and
(System[(Computer!='comp14')]) and
(System[(Computer!='comp15')])]
This query works fine unless I add one more condition
and [(Computer!='comp16')])
After that filter stops working and all logs are displayed.
Notice that if I put comp16 instead of comp15 or instead of comp12 everything works fine. So problem is not in the new condition.
The situation is opposite if I use equality filter
(System[(Computer='comp1')]) or
(System[(Computer='comp2')]) or
...
(System[(Computer='comp15')]) or
(System[(Computer='comp16')]) and so on
Filter works fine with much larger queries.
So why not equal operator does not work in large queries?
EDIT
Filter by EventRecordID has the same problem
EDIT 2
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Microsoft-Windows-Security-Auditing" Guid="{54849625-5478-4994-A5BA-3E3B0328C30D}" />
<EventID>4624</EventID>
<Version>1</Version>
<Level>0</Level>
<Task>12544</Task>
<Opcode>0</Opcode>
<TimeCreated SystemTime="2017-08-18T17:06:15.595105400Z" />
<EventRecordID>1</EventRecordID>
<Correlation />
<Execution ProcessID="584" ThreadID="7100" />
<Channel>Security</Channel>
<Computer>comp1</Computer>
<Security />
</System>
<EventData>
<Data Name="TargetUserName">userName</Data>
<Data Name="TargetDomainName">DOMAIN</Data>
...
<Data Name="ProcessName">-</Data>
<Data Name="IpAddress">-</Data>
<Data Name="IpPort">-</Data>
</EventData>
</Event>
You haven't shown your XML, but it's hard to envisage an XML structure on which this query makes any sense.
Consider the simpler
*[(System[(Computer!='comp1')]) and
(System[(Computer!='comp2')])]
If there is only one System with only one Computer, then this returns true if the Computer is neither 'comp1' nor 'comp2'. But if there is more than one System, or more than one Computer, and if the Computers are not all the same value, then there will inevitably be at least one Computer that is not 'comp1', and at least one that is not 'comp2', and the predicate will therefore always be true.
Usually when people write A!=B in XPath, they should have written not(A=B).

FHIR Element Definition max/min

What does max/min mean on the root element of a resource or extension?
<element>
<path value="Patient" />
<min value="0" />
<max value="*" />
...snip...
</element>
The cardinality allowed in a containing structure like Bundle? Doesn't make sense to me....
For a resource, it doesn't mean anything. For an extension, it places constraints on what the cardinality is allowed to be for a slice instantiating that constraint in a profile. For example, if an extension has a cardinality of 1..5, then if that extension is referenced inside a profile, the minimum cardinality of that constraint element must be at least 1 and the maximum no more than 5. Most of the time this will just be used to indicate whether the extension will be allowed to repeat or not.

How to set value in expression for scheme in BizTalk orchestration?

When I want to compile, an error shown
use of unconstructed message
My code for expression is:
Message_2.Approved == false
XML code in scheme Article.xsd:
<xs:element name="Approved">
<xs:simpleType>
<xs:restriction base="xs:boolean" />
</xs:simpleType>
</xs:element>
Message_2 is assigned to assigned to a Send shape.
And Message Type of Message_2 is BizTalk_Server_Project7.Article .
It looks like there is something wrong with your property promotion.
You are trying to use 'Approved' as a distinguished field in your expression shape to set a value, which is perfect use of a distinguished field. Please review this tutorial on MSDN if you did everything right.
make sure that the used property is promoted or distinguished before can be used in your orchestration's expression shape. if your property will be used only in messagebox context and not outside(filters or pipelines) you can make simple and use distiguished field.

Use Xpath to select all nodes that extend from base class in xsd

My xsd file is like follows:
<xs:complexType name="baseClass">
</xs:complexType>
<xs:complexType name="childClass1">
<xs:complexContent>
<xs:extension base="baseClass">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="childClass2">
<xs:complexContent>
<xs:extension base="baseClass">
</xs:extension>
</xs:complexContent>
</xs:complexType>
Is there a way to use xpath to select childClass1, childClass2, and all the types that extend from baseClass, without selecting all the childClass individually?
The set of all the complex types declared in a given schema document that extend baseClass directly can be found with
//xs:complexType[xs:complexContent/xs:extension[#base='baseClass']]
If you need not only childClass1 and childClass2 and so on but also all the types that extend them (and thus extend baseClass in one or more steps), however, you're going to have to move some of the logic from XPath into some host language and loop over the elements. What you want to do can be expressed in the following pseudo-code:
Start with an empty queue and an empty accumulator.
Push baseClass onto the queue.
If the queue is empty, the set of types you want is in the accumulator. Stop.
(If you reach this step, the queue is not empty.) Remove the first item from the queue; let $x denote its name, if it has one, otherwise let $x be the empty string.
Find the set //xs:complexType[xs:complexContent/xs:extension[#base=$x]]. Add them both to the queue and to the accumulator.
Go to step 3.
Note that the XPath expressions I have written will find all complex types extending a given named base; if you want only named complex types, change the // at the beginning to /xs:schema/.

Resources