Validate Xml without using xmlns
-
Hi, I have the xml document like, <?xml version="1.0" encoding="utf-8"?> <Drive> <folders> <folder name="f1"> </folder> <folder name="f2"> </folder> </folders> </Drive> Please notice that there is no xmlns used and I cannot used xmlns in this xml document. I have problem creating schema (.xsd) file to validate this xml document. My schema is like <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.tempuri.com/temp" elementFormDefault="qualified"> <element name="Drive"> <complexType> <sequence> <element ref="folders" minOccurs="0" maxOccurs="1"/> </sequence> </complexType> </element> <element name ="folders"> <complexType> <sequence minOccurs ="0" maxOccurs ="unbounded"> <element ref ="folder"/> </sequence> </complexType> </element> <element name ="folder"> <complexType> <sequence> <element ref ="folders" minOccurs ="0" maxOccurs="1" /> </sequence> <attribute name ="name" type="string" /> </complexType> </element> </schema> But the ref attribute is not working. ie the attribute 'folders' cannot reference the element 'folders'. I am using VS2008 to create/edit xsd file. VS2008 shows warning message "The 'http://www.w3.org/2001/XMLSchema:folders' element is not declared.". The same exception occurs if I run my c# program to valid the xml. Could you please suggest me how to refernce element using ref attribute without using namespace? Is there any other workaround? Thanks. Prakash
-
Hi, I have the xml document like, <?xml version="1.0" encoding="utf-8"?> <Drive> <folders> <folder name="f1"> </folder> <folder name="f2"> </folder> </folders> </Drive> Please notice that there is no xmlns used and I cannot used xmlns in this xml document. I have problem creating schema (.xsd) file to validate this xml document. My schema is like <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.tempuri.com/temp" elementFormDefault="qualified"> <element name="Drive"> <complexType> <sequence> <element ref="folders" minOccurs="0" maxOccurs="1"/> </sequence> </complexType> </element> <element name ="folders"> <complexType> <sequence minOccurs ="0" maxOccurs ="unbounded"> <element ref ="folder"/> </sequence> </complexType> </element> <element name ="folder"> <complexType> <sequence> <element ref ="folders" minOccurs ="0" maxOccurs="1" /> </sequence> <attribute name ="name" type="string" /> </complexType> </element> </schema> But the ref attribute is not working. ie the attribute 'folders' cannot reference the element 'folders'. I am using VS2008 to create/edit xsd file. VS2008 shows warning message "The 'http://www.w3.org/2001/XMLSchema:folders' element is not declared.". The same exception occurs if I run my c# program to valid the xml. Could you please suggest me how to refernce element using ref attribute without using namespace? Is there any other workaround? Thanks. Prakash
I may have steered you wrong before saying that ref didn't work without namespaces. I think they do, but there are a few things that need to change before your schema could possibly work:
-
Remove the targetNamespace attribute - this is the namespace that the elements your defining in the schema (Drive, folder
-
You need to change the default namespace declaration to be a named namespace:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
and prefix all elements that come from the XML Schema namespace with the namespace prefix you choose (xs in this case)
Oh and one other thing - learn about XML namespaces, what they imply and how they interact with XML Schemas. You need to know this stuff if you're going to design XML Schemas - you need to know it if you're working with XML!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
-
Hi, I have the xml document like, <?xml version="1.0" encoding="utf-8"?> <Drive> <folders> <folder name="f1"> </folder> <folder name="f2"> </folder> </folders> </Drive> Please notice that there is no xmlns used and I cannot used xmlns in this xml document. I have problem creating schema (.xsd) file to validate this xml document. My schema is like <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.tempuri.com/temp" elementFormDefault="qualified"> <element name="Drive"> <complexType> <sequence> <element ref="folders" minOccurs="0" maxOccurs="1"/> </sequence> </complexType> </element> <element name ="folders"> <complexType> <sequence minOccurs ="0" maxOccurs ="unbounded"> <element ref ="folder"/> </sequence> </complexType> </element> <element name ="folder"> <complexType> <sequence> <element ref ="folders" minOccurs ="0" maxOccurs="1" /> </sequence> <attribute name ="name" type="string" /> </complexType> </element> </schema> But the ref attribute is not working. ie the attribute 'folders' cannot reference the element 'folders'. I am using VS2008 to create/edit xsd file. VS2008 shows warning message "The 'http://www.w3.org/2001/XMLSchema:folders' element is not declared.". The same exception occurs if I run my c# program to valid the xml. Could you please suggest me how to refernce element using ref attribute without using namespace? Is there any other workaround? Thanks. Prakash
You have referenced the element 'folders' before it was described in your xml that is why you are getting this error. Try changing the order in your xml . <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.tempuri.com/temp" elementFormDefault="qualified"> <element name ="folders"> <complexType> <sequence minOccurs ="0" maxOccurs ="unbounded"> <element ref ="folder"/> </sequence> </complexType> </element> <element name="Drive"> <complexType> <sequence> <element ref="folders" minOccurs="0" maxOccurs="1"/> </sequence> </complexType> </element> <element name ="folder"> <complexType> <sequence> <element ref ="folders" minOccurs ="0" maxOccurs="1" /> </sequence> <attribute name ="name" type="string" /> </complexType> </element> </schema> Regards Akhila