Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Validate Xml without using xmlns

Validate Xml without using xmlns

Scheduled Pinned Locked Moved XML / XSL
xmlcsharpdatabasecomhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tprakash
    wrote on last edited by
    #1

    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

    S R 2 Replies Last reply
    0
    • T tprakash

      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

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      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:

      1. Remove the targetNamespace attribute - this is the namespace that the elements your defining in the schema (Drive, folder

      2. 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

      1 Reply Last reply
      0
      • T tprakash

        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

        R Offline
        R Offline
        Roll 1
        wrote on last edited by
        #3

        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"> &lt;element name ="folders"&gt; &lt;complexType&gt; &lt;sequence minOccurs ="0" maxOccurs ="unbounded"&gt; &lt;element ref ="folder"/&gt; &lt;/sequence&gt; &lt;/complexType&gt; &lt;/element&gt; <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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups