473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Validation ignores fixed attribute

hi @all,

I'm trying to validate a XML against a schema using the example from the
MSDN:

http://msdn.microsoft.com/en-us/libr...ationtype.aspx

In my case this seems to validates my file, because the
ValidationCallBack handler is not called.
But the file is invalid due to a wrong fixed attribute.

I don't know why, so any clue is appreciated.

My GPX (GPS Exchange Format) file:

<?xml version="1.0"?>
<gpx
version="1.0"
creator="Holux Utility"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0
http://www.topografix.com/GPX/1/0/gpx.xsd">

<wpt lat="48.342567" lon="10.865602">
<ele>137.59</ele>
<time>2008-09-03T15:17:23Z</time>
<name><![CDATA[Point 0]]></name>
</wpt>

<wpt lat="48.342548" lon="10.865611">
<ele>137.72</ele>
<time>2008-09-03T15:17:24Z</time>
<name><![CDATA[Point 1]]></name>
</wpt>

</gpx>

My code looks like this (.Net 3.5, dlgFileOpen.FileName points to the
file above):

XmlSchemaSet sc = new XmlSchemaSet();
sc.Add("http://www.topografix.com/GPX/1/1", "Resources\\gpx-1.1.xsd");

XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = sc;
settings.ValidationEventHandler += new
ValidationEventHandler(ValidationCallBack);

XmlReader reader = XmlReader.Create(dlgFileOpen.FileName, settings);
while (reader.Read()) ;

mfG
--stefan <--
Sep 4 '08 #1
4 2082
Stefan Hoffmann wrote:
<gpx
version="1.0"
creator="Holux Utility"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
So here the namespace URI is http://www.topografix.com/GPX/1/0
while later on you add a schema for
XmlSchemaSet sc = new XmlSchemaSet();
sc.Add("http://www.topografix.com/GPX/1/1", "Resources\\gpx-1.1.xsd");
http://www.topografix.com/GPX/1/1 which is different. Make sure you add
a schema for the namespace your XML instance document uses, otherwise
validation will only emit some warnings that no matching schema is found
and your code
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = sc;
settings.ValidationEventHandler += new
ValidationEventHandler(ValidationCallBack);
will not even so those warnings as you do not have the ValidationFlags
set on your settings object to ReportValidationWarnings.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 4 '08 #2
hi Martin,

Martin Honnen wrote:
will not even so those warnings as you do not have the ValidationFlags
set on your settings object to ReportValidationWarnings.
Thanks.

btw, is there any idiom to detect the necessary schema for a XML file?
In my GPX case there are two schemas.

I'm considering using this for the XmlReaderSettings.Schemas:

XmlSchemaSet sc = new XmlSchemaSet();
sc.Add("http://www.topografix.com/GPX/1/0", "Resources\\gpx-1.0.xsd");
sc.Add("http://www.topografix.com/GPX/1/1", "Resources\\gpx-1.1.xsd");

So when the validation handler is not called, then one schema applies to
the file.

Is this correct?

mfG
--stefan <--
Sep 4 '08 #3
Stefan Hoffmann wrote:
btw, is there any idiom to detect the necessary schema for a XML file?
In my GPX case there are two schemas.

I'm considering using this for the XmlReaderSettings.Schemas:

XmlSchemaSet sc = new XmlSchemaSet();
sc.Add("http://www.topografix.com/GPX/1/0", "Resources\\gpx-1.0.xsd");
sc.Add("http://www.topografix.com/GPX/1/1", "Resources\\gpx-1.1.xsd");

So when the validation handler is not called, then one schema applies to
the file.
The validating parser will look at the namespace of the root element of
the XML document to be validated and then check for a schema with a
matching targetNamespace in its XmlSchemaSet. If it does not find a
matching schema then a warning is issued. If a matching schema is found
the parser checks whether there is a top level defintion for the root
element and validates against that definition, reporting errors as
needed to the handler. If there is no top level definition for the root
element then this is also an error. So the above should work.

Note that you can shorten the code, there is no need to explicitly
create and assing an XmlSchemaSet, you can simply call
settings.Schemas.Add. And passing in the schema URI to the Add method is
not necessary, if you pass in null for that parameter then it simply
uses the targetNamespace of the schema passed in as the second argument.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 4 '08 #4
hi Martin,

Martin Honnen wrote:
>XmlSchemaSet sc = new XmlSchemaSet();
sc.Add("http://www.topografix.com/GPX/1/0", "Resources\\gpx-1.0.xsd");
sc.Add("http://www.topografix.com/GPX/1/1", "Resources\\gpx-1.1.xsd");
Note that you can shorten the code, there is no need to explicitly
create and assing an XmlSchemaSet, you can simply call
settings.Schemas.Add. And passing in the schema URI to the Add method is
not necessary, if you pass in null for that parameter then it simply
uses the targetNamespace of the schema passed in as the second argument.
Ah, cool. Thanks a lot.
mfG
--stefan <--
Sep 4 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert Smith | last post by:
I have a very basic form validation script, which wont work due to XHTML Strict not allowing me to use the name attribute on a form. Here is part of my code: if...
6
by: MickG | last post by:
Hi, I am trying to validate these values, this seems to work fine for the phone number and name but I am trying to get the program to fail to submit and set the focus on the date when 2006 is...
14
by: Brandon | last post by:
I am an amateur working on a first site, I have settled on using FP 2002 for now. My current page is up and live, but I have two errors that I cant seem to get rid of ... Line 29, column 6:...
1
by: johnmack | last post by:
In my XML instances I want to use the XLink namespace for attributes on certain elements. I'm having quite a hard time determining how to reflect this properly in my DTD and XML instances. In...
1
by: Hong Hao | last post by:
Recently, I was trying to modify an existing aspx page when client-side validation on that page stopped working. I searched this group and the web in general and found that other people have had...
6
by: uttara | last post by:
Hello All, I was trying to validate an XML document against a XSD which works fine. Then I tried to put in a version attribute on the root element and set it to a fixed value of '1.0' in the...
3
by: mightyreds | last post by:
I have started again after my previous effort had so many errors. the url is http://www.freebetsonline.info/freebets2.html. using the w3c validation page I have 5 errors, four are the same...
0
by: tanish2k | last post by:
hi. I am using c#, visual studio 2003. I need to validate a xml file against schema which itself has 2 more schema imported under it. i have following 2 xsd files : xsd1 --->...
8
by: Bryan | last post by:
I want my business objects to be able to do this: class Person(base): def __init__(self): self.name = None @base.validator def validate_name(self): if not self.name: return
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.