Reputation: 2841
I have a xsd file. For every xs:element inside xs:sequence, I want to convert them to <Class></Class>
. So for this file below, the output should contain 3 times of <Class></Class>
.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="contacts">
<xs:complexType>
<xs:sequence>
<xs:element ref="contact"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="contact">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:NCName"/>
<xs:element name="lastname" type="xs:NCName"/>
</xs:sequence>
<xs:attribute name="citizen" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
But instead I got this:
$ zorba -i -f -q test.xqy
<?xml version="1.0" encoding="UTF-8"?>
<Class/>
<Class/>
This output looks so strange. I dont have <Class/>
in the xqy file.
xqy file:
for $x in doc("test.xsd")/xs:schema/xs:element/xs:complexType/xs:sequence
return <Class>
</Class>
Upvotes: 0
Views: 271
Reputation: 884
You could improve the XPath part with /*
because you are searching for children of the xs:sequence
:
XQuery 3.0
for $x in doc("test.xsd")/xs:schema/xs:element/xs:complexType/xs:sequence/*
return <Class></Class>
With this I have:
<?xml version="1.0" encoding="UTF-8"?>
<Class/>
<Class/>
<Class/>
Upvotes: 0
Reputation: 3056
In XML, <Class></Class>
and <Class/>
are equivalent nodes with mere serialization differences. Your XQuery processor is removing the whitespace between <Class>
and </Class>
. You could try setting serialization options for the processor, or added <Class xml:space="preserve">
.
Upvotes: 0