473,804 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Validation: required attributes

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 schema. Guess what? The
validator completely ignores the attribute inspite of the fact that I
have set the attribute to be required and to have a fixed value of '1.0'.
Any ideas why that could be happening. Any help is appreciated.
Uttara
Dec 21 '05 #1
6 5030
Either you didn't do what you thought you did or the validator has a
problem. Which validator did you use and what are your schema/instance?

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
"uttara" <pl*******@hotm ail.com> wrote in message
news:OQ******** ******@TK2MSFTN GP11.phx.gbl...
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 schema. Guess what? The validator
completely ignores the attribute inspite of the fact that I have set the
attribute to be required and to have a fixed value of '1.0'.
Any ideas why that could be happening. Any help is appreciated.
Uttara

Dec 22 '05 #2
Stan,
I won't be utterly surprised if I missed out something. I am using the
XMLValidatingRe ader. Here is the schema I am using:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Schema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Products" >
<xs:complexType >
<xs:sequence>
<xs:element name="ItemCode" minOccurs="1"
maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="SKU" type="xs:string "
minOccurs="0" maxOccurs="unbo unded" />
</xs:sequence>
<xs:attribute name="code" type="xs:string " />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="schemaVer sion" type="xs:decima l"
use="required" fixed="1.0" />
</xs:complexType>
</xs:element>
</xs:schema>

Here is the instance
<?xml version="1.0" encoding="utf-8" ?>
<Products schemaVersion=" 1.1">
<ItemCode code="10098"></ItemCode>
<ItemCode code="10047">
<SKU>0023</SKU>
<SKU>0025</SKU>
</ItemCode>
</Products>

Thanks again,
Uttara

Stan Kitsis [MSFT] wrote:
Either you didn't do what you thought you did or the validator has a
problem. Which validator did you use and what are your schema/instance?

Dec 22 '05 #3
I get the following warning using .net 2.0: "The value of the
'schemaVersion' attribute does not equal its fixed value."

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
"uttara" <pl*******@hotm ail.com> wrote in message
news:e1******** ******@TK2MSFTN GP11.phx.gbl...
Stan,
I won't be utterly surprised if I missed out something. I am using the
XMLValidatingRe ader. Here is the schema I am using:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Schema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Products" >
<xs:complexType >
<xs:sequence>
<xs:element name="ItemCode" minOccurs="1"
maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="SKU" type="xs:string "
minOccurs="0" maxOccurs="unbo unded" />
</xs:sequence>
<xs:attribute name="code" type="xs:string " />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="schemaVer sion" type="xs:decima l"
use="required" fixed="1.0" />
</xs:complexType>
</xs:element>
</xs:schema>

Here is the instance
<?xml version="1.0" encoding="utf-8" ?>
<Products schemaVersion=" 1.1">
<ItemCode code="10098"></ItemCode>
<ItemCode code="10047">
<SKU>0023</SKU>
<SKU>0025</SKU>
</ItemCode>
</Products>

Thanks again,
Uttara

Stan Kitsis [MSFT] wrote:
Either you didn't do what you thought you did or the validator has a
problem. Which validator did you use and what are your schema/instance?

Dec 22 '05 #4
Hmm...what if we take out the schemaVersion attribute from the root
element so it looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<Products>
<ItemCode code="10098"></ItemCode>
<ItemCode code="10047">
<SKU>0023</SKU>
<SKU>0025</SKU>
</ItemCode>
</Products>
Stan Kitsis [MSFT] wrote: I get the following warning using .net 2.0: "The value of the
'schemaVersion' attribute does not equal its fixed value."

Dec 22 '05 #5
This should be invalid since the version attribute is required.

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

"uttara" <pl*******@hotm ail.com> wrote in message
news:uQ******** ******@TK2MSFTN GP10.phx.gbl...
Hmm...what if we take out the schemaVersion attribute from the root
element so it looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<Products>
<ItemCode code="10098"></ItemCode>
<ItemCode code="10047">
<SKU>0023</SKU>
<SKU>0025</SKU>
</ItemCode>
</Products>


Stan Kitsis [MSFT] wrote:
I get the following warning using .net 2.0: "The value of the
'schemaVersion' attribute does not equal its fixed value."

Dec 23 '05 #6
The following code does produce the warning:
"The value of the 'schemaVersion' attribute does not equal its fixed
value."
static void Main(string[] args) {
Directory.SetCu rrentDirectory( "..\\..");

ValidationEvent Handler handler = new
ValidationEvent Handler(OnValid ationEvent);
XmlTextReader reader = new XmlTextReader(" test.xml");
XmlValidatingRe ader validator = new XmlValidatingRe ader(reader);
validator.Schem as.Add(XmlSchem a.Read(new
StreamReader("t est.xsd"), handler));
validator.Valid ationType = ValidationType. Schema;
validator.Valid ationEventHandl er += handler;
while (validator.Read ()) {
}
return;
}

static void OnValidationEve nt(object sender, ValidationEvent Args e)
{
Console.WriteLi ne(e.Message);
}

"uttara" <pl*******@hotm ail.com> wrote in message
news:e1******** ******@TK2MSFTN GP11.phx.gbl...
Stan,
I won't be utterly surprised if I missed out something. I am using the
XMLValidatingRe ader. Here is the schema I am using:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Schema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Products" >
<xs:complexType >
<xs:sequence>
<xs:element name="ItemCode" minOccurs="1"
maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="SKU" type="xs:string "
minOccurs="0" maxOccurs="unbo unded" />
</xs:sequence>
<xs:attribute name="code" type="xs:string " />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="schemaVer sion" type="xs:decima l"
use="required" fixed="1.0" />
</xs:complexType>
</xs:element>
</xs:schema>

Here is the instance
<?xml version="1.0" encoding="utf-8" ?>
<Products schemaVersion=" 1.1">
<ItemCode code="10098"></ItemCode>
<ItemCode code="10047">
<SKU>0023</SKU>
<SKU>0025</SKU>
</ItemCode>
</Products>

Thanks again,
Uttara

Stan Kitsis [MSFT] wrote:
Either you didn't do what you thought you did or the validator has a
problem. Which validator did you use and what are your schema/instance?

Dec 23 '05 #7

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

Similar topics

4
1497
by: ian.rutgers | last post by:
In validating http://www.otima.ca/XML/auto.xml (auto.xsd) I get the following error: "Attribute 'make' should be qualified" If you look at my schema i do havit it qualified, so I don't understand! Please, someone, set me right. Thank you, Ian
1
2073
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 my instance, to declare the namespace, I have this on my root element: <root xmlns:xlink="http://www.w3.org/1999/xlink"> ... <mylink xlink:href="http://foo.com"> ....
7
2876
by: A.M | last post by:
Hi, I have a validation control in my page that upon any invalid data, it disables all buttons in the page. basicly i don't have any postback in the page if the validator finds any error. How can have the validator just disable certain control's postback and other part of page continue their functionality. Thanks,
2
2091
by: Fourge | last post by:
Hi, I have run into a very strange scenario. In developing an ASP.NET application on framework version 1.1, I found that certain client-side validation scripts were not being rendered. The reason we came up with for this was because we had a PageBase base class for all our pages. This base class takes the controls on the child page class and places them onto the form being rendered. It seems that in this process, the rendering of the...
1
3907
by: Bruce | last post by:
I use btnSave.Attributes.Add("onclick", "ShowMessage()") to link my web control button to a JavaScript function. It works well until I added a Validation control into the page. After that, even the all of the validations passed, my ShowMessage() still does not get triggered. When checking the view source carefully, I found that the btnSave button have 2 onClick events defined in the tag.
2
2370
by: daniel.boorn | last post by:
Form validation using JavaScript has never been as easy and simple! We have developed a free generic form validation script that can validate any form with very little JavaScript required in form! For example: A normal HTML form with out validation: <form action="foobar.htm" method="get"> <div>Name: <input type="text" name="customerName" value=""></div>
11
3004
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
1
1450
by: Drew Wildner | last post by:
Hello grp: Given the following scenario, I'm hoping someone can suggest the best method for accomplishing xml validation. We have a system that accepts requests in the form of xml messages. We publish schemas detailing the contents and constraints of these requests. The service is available to both outside and internal consumers. We use xsd.exe to generate a 'type-safe' document from these schemas. The document structure is too...
0
5296
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all the days in the week with dates and textboxes to fill in some data. row 1: question
5
1618
by: forest demon | last post by:
i'm trying to create a .xsd file to validate the XML below(just a small snippet). i've tried a number of things and can come close, but i can't quite get it to do what i want. i'm able to validate the snippet below using .NET with a schema that will make sure that the six attributes are correct in spelling, but that's about it. i would like it to be able to: 1) make sure each element(tool) is correct by having all the six attributes...
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10354
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10359
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3005
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.