Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
You use namespaces by declaring in your XML document that a particular set of elements belong to a given namespace. That has nothing to do with where your XML Schema document resides (even if a namespace looks like a URL, there usually isn't anything behind that URL if you type the URL into a browser!).Originally posted by Saritha ventrapragada:
My problem is I am not sure how to define and use these namespaces.
Dose it has got something to do with location where my schema reside. How both are linked?.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Saritha ventrapragada:
My doubt is schemaLocation attribute. I guess validator look for the schema file using the namespace URI and schema URI that I give in schemaLocation attribute. Please correct me if I am wrong.
I am guessing that the errors are due to validator not being able to locate the schema file. As the validator I am using is on the web. I am uploading xml and xsd file into the this site
I guess that validator is looking for report.xsd file in localhost which it can never find.
Please let me know if my understanding is wrong.
I really appreciate all your patience with me and thank you very much for helping me
saritha
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Originally posted by Saritha ventrapragada:
when elementFormDefault=unqualified, then all the elements are localized and there is will be no requirement to explicitly qualify them, hence I thought I am good with not declaring that element.
Not really. While your understanding is correct, what you missed here
is the concept of default namespace. When you don't qualify an element
with a prefix, it is considered to be in the default namespace. Hence,
based on your original code you had
Report xmlns="http://localhost/Report"
This becomes your default namespace. Hence, all unqualified elements
are assumed to belong to this namespace. But based on the way you defined
the schema and the targetNamespace, they are not part of the namespace.
Hence the problems.
Why do the local elements do not come under targetnamespace when their parent element is?
That's by definition of the XML Schema recommentations.
Even when i gave value of highlight="yes" than "true" i was getting same error.
The errors were because of the namespace. Once, the element was properly
defined, then it looked at the definition of the attributes for the
element in that namespace and so the attribute highlight was then
validated to be wrong according to the definition given in the schema.
I would really appreciate if you could suggest me some good URL's to understand all these concepts correctly.
I think you need to understand two concepts really to solve this.
1. Namespaces in XML.
2. Namespaces in XML Schema. Not sure how useful this link is.
Another article in Namespaces.
There was another link on namespace Faq, can't locate it at the moment.
Also, Definitive XML Schema by Priscilla Walmsley, book talk a lot about this topic.
Thanks.
- m
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Error at (38,14): The 'hightlight' attribute is not declared. An error occurred at , (38, 14).
<ReportData hightlight = "true">
<Data>123456</Data>
<Data>12/04/2004</Data>
<Data>KSDF</Data>
<Data>CSDK</Data>
<Data>10000</Data>
</ReportData>
Schema declaration
<?xml version="1.0" encoding="iso-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://localhost/Report"
targetNamespace="http://localhost/Report"
elementFormDefault="qualified"
>
<xs:element name="Report" type="ReportType" />
<xs:complexType name="ImageType">
<xs:attribute name="img" type="xs:anyURI" use="required"/>
<xs:attribute name="width" type="xs :p ositiveInteger" use="required"/>
<xs:attribute name="height" type="xs :p ositiveInteger" use="required"/>
<xs:attribute name="alt" type="xs:string"/>
</xs:complexType>
<xs:complexType name="FieldInfoType">
<xs:sequence>
<xs:element name="FieldLabel" type="xs:string" />
<xs:element name="FieldValue" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="CriteriaType">
<xs:sequence>
<xs:element name="FieldInfo" type="FieldInfoType" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ReportHeaderType">
<xs:sequence>
<xs:element name="Header" type="xs:string" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ReportDataType">
<xs:sequence>
<xs:element name="Data" type="xs:string" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="highlight" type="xs:boolean" />
</xs:complexType>
<xs:complexType name="ReportTotalsType">
<xs:sequence>
<xs:element name="FieldInfo" type="FieldInfoType" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="EmptyType">
</xs:complexType>
<xs:complexType name="ReportType">
<xs:sequence>
<xs:element name="HeaderImage" type="ImageType" minOccurs="0" maxOccurs="1"/>
<xs:element name="BR" type="EmptyType" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="Title" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="Subtitle" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="Criteria" type="CriteriaType"/>
<xs:element name="ReportHeader" type="ReportHeaderType"/>
<xs:element name="ReportData" type="ReportDataType" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="ReportTotals" type="ReportTotalsType" minOccurs="0" maxOccurs="1" />
<xs:element name="FooterImage" type="ImageType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
mat_hues