XML Namespace confusion
-
Hi... I have createds a XML document (chart.xml) along with a seperate XML Schema (chart.xsd) document to describe the structure of the XML document and its data types. My confusion comes in (after trying the w3CSchools explanation unsuccessfully) when namespaces need to be applied. All I want to do is get the XML document to reference this XSD document (which are located in the same folder) so that value and elements within the XML document are of the correct format (this is what schema is for is it not?). Also how can I tell its working properly? Any help/pointers would be very appreicated. Ta John XML CODE---------------------------------------- Mon Tue Wed Thu Fri Sat Sun 45 50 30 10 30 50 70 600 400 Days of the month Total man hours Daily Studio man hours 50 50 30 20 Schema CODE-------------------------------------
-
Hi... I have createds a XML document (chart.xml) along with a seperate XML Schema (chart.xsd) document to describe the structure of the XML document and its data types. My confusion comes in (after trying the w3CSchools explanation unsuccessfully) when namespaces need to be applied. All I want to do is get the XML document to reference this XSD document (which are located in the same folder) so that value and elements within the XML document are of the correct format (this is what schema is for is it not?). Also how can I tell its working properly? Any help/pointers would be very appreicated. Ta John XML CODE---------------------------------------- Mon Tue Wed Thu Fri Sat Sun 45 50 30 10 30 50 70 600 400 Days of the month Total man hours Daily Studio man hours 50 50 30 20 Schema CODE-------------------------------------
-
--XML CODE------------------------------------------------ Mon Tue Wed Thu Fri Sat Sun 45 50 30 10 30 50 70 600 400 Days of the month Total man hours Daily Studio man hours 50 50 30 20 --XSD CODE------------------------------------------------
Namespaces are used to qualify elements and attributes. They aren't necessary, but are usually a good idea so that you can easily qualify elements and attributes when using XML documents with mixed content. To use them, add the
xs:targetNamespace
(wherexs
is the namespace prefix for XMLSchemas) and then use the same namespace to qualify your XML document that you gave first. To use it as the default namespace, usexmlns="....."
with no prefix. When you're using code to access the DOM, you can use any prefix you want, so long as the namespace in the namespace manager (in .NET, this is theXmlNamespaceManager
) matches (case-sensitively) the namespace declared in the document.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----