By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

validate element with attribute xsi:type="xsd:string"

P: n/a
How do you validate the following XML document, I'm having problems
with element 'one' with the attribute xsi:type="xsd:string"

<?xml version="1.0" encoding="UTF-8"?>
<zero xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<one xsi:type="xsd:string">test</one>
</zero>

Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a


jo******@gmail.com wrote:
How do you validate the following XML document, I'm having problems
with element 'one' with the attribute xsi:type="xsd:string"

<?xml version="1.0" encoding="UTF-8"?>
<zero xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<one xsi:type="xsd:string">test</one>
</zero>


To validate you need a schema I think, I don't know any validators
checking the xsi:type attribute alone.
And of course you need to bind the prefix xsd e.g.
<zero
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2

P: n/a
I've been working with the following schema without luck.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

<xsd:element name="zero">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="one" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="one" type="xsd:string"/>

<xsd:complexType name="xsd:string">
<xsd:simpleContent>
<xsd:extension base="xsd:string"/>
</xsd:simpleContent>
</xsd:complexType>
</xsd:schema>

Jul 20 '05 #3

P: n/a


jo******@gmail.com wrote:
I've been working with the following schema without luck.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

<xsd:element name="zero">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="one" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="one" type="xsd:string"/>

<xsd:complexType name="xsd:string">
<xsd:simpleContent>
<xsd:extension base="xsd:string"/>
</xsd:simpleContent>
</xsd:complexType>


Why are you trying to redefine xsd:string then?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4

P: n/a
I'm trying to write a schema to validate the xml document, and I dont
know how to handle the one element. Based on the following I came up
with the previous schema.

<?xml version="1.0" encoding="UTF-8"?>
<zero xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<one xsi:type="A">test</one>
</fullName>

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

<xsd:element name="zero">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="one" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="one" type="A"/>

<xsd:complexType name="A">
<xsd:simpleContent>
<xsd:extension base="xsd:string"/>
</xsd:simpleContent>
</xsd:complexType>

</xsd:schema>

Jul 20 '05 #5

P: n/a


jo******@gmail.com wrote:
I'm trying to write a schema to validate the xml document, and I dont
know how to handle the one element.


The schema is simple but you need to bind the prefix xsd as already
explained:

<?xml version="1.0" encoding="UTF-8"?>
<zero xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test2005060801Xsd.x ml"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<one xsi:type="xsd:string">test</one>
</zero>

then the schema looks as

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="zero">
<xs:complexType>
<xs:sequence>
<xs:element name="one" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #6

P: n/a
Thanks!

Jul 20 '05 #7

P: n/a
If you could help me out with more more thing that would be great, you
have been very helpful.

Again trying to build a schema based on the following XML. I
understand how to describe the 'one' element I dont understand how to
describe the soap message within the schema.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>

<one xsi:type="xsd:string>test</one>

</soapenv:Body>
</soapenv:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
version="1.0">

<xsd:element name="zero">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="one" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

</xsd:schema>

Thanks in advance.

Jul 20 '05 #8

P: n/a


jo******@gmail.com wrote:
If you could help me out with more more thing that would be great, you
have been very helpful.

Again trying to build a schema based on the following XML. I
understand how to describe the 'one' element I dont understand how to
describe the soap message within the schema.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>

<one xsi:type="xsd:string>test</one>

</soapenv:Body>
</soapenv:Envelope>


You need to have two schemas then as one schema can only describe the
elements in one particular target namespace while your XML instance
above has elements in the namespace
http://schemas.xmlsoap.org/soap/envelope/ and in no namespace.

So a possible solution is

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://schemas.xmlsoap.org/soap/envelope/"
version="1.0">

<xs:import schemaLocation="test2005060902Xsd.xml" />

<xs:element name="Envelope">
<xs:complexType>
<xs:sequence>
<xs:element name="Body">
<xs:complexType>
<xs:sequence>
<xs:element ref="one" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

where the imported schema test2005060902Xsd.xml is

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="one" type="xs:string" />

</xs:schema>

and the instance is

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
test2005060901XSd.xml">
<soapenv:Body>
<one xsi:type="xsd:string">test</one>
</soapenv:Body>
</soapenv:Envelope>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.