-
xsd Node Question
Hey all,
is it possible to declare that all content of a node is only seen as text till that node ends?
So that an xml document like this
Code:
<Data>myText</Data>
and a document like this
Code:
<Data><myNewDoc></myNewDoc></Data>
would both be valid and could be parsed against one Schema?
Thanks,
Stephan
-
Sheesh how frustrating! I battled with that for SOOOO long! Anyway, here she is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="data">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType mixed="true">
<xs:sequence>
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
-
How did you test it?
I always get an error message saying
C:\test\test_element.xml Could not find schema information for the element 'myNewDoc'. An error occurred at file:///C:/test/test_element.xml, (2, 8).
So it validates the one with only text but not the one with another element in it.
Stephan
-
If you want the "inner element" to be parsed as pure text, you can use a CDATA node:
Code:
<outer><![CDATA[<inner></inner>]]></outer>
The inner element won't be parsed, you'll get it as a literal string.
-
Sorry, still the same error.
-
Exactly the same? Then the parser is buggy...
Which parser do you use?
-
I am doing the validation in Microsofts BizTalk Server 2004. So it should be MSXML right?
-
Let me check it again. But I am pretty sure it worked.
-
I used xml spy to validate the documents.
The one with just a node:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XML Spy v4.4 U (http://www.xmlspy.com)-->
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="E:\DayneO\My Documents\Business Associates\DPO Solutions\Examples\node_with_any_child.xsd">
<myNewDoc></myNewDoc>
</data>
The one with just text:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XML Spy v4.4 U (http://www.xmlspy.com)-->
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="E:\DayneO\My Documents\Business Associates\DPO Solutions\Examples\node_with_any_child.xsd">
text
</data>
-
Post your xml document and schema so I can see the exact structure.
-
I'll post it tomorrow, when I am back in work!
Thanx all,
Stephan