473,473 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help needed with .xsd validation

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 present/required.
2) that each attribute is spelled correctly and consists of a string.

the .xsd is below as well.

i can't find any examples that address the way i have my elements and
attributes structured. i really don't want to have to redo my XML
file to conform to the way my .xsd validates! that just seems silly
and a cop-out to me. am i stubborn you ask? well, yeah!!! :-)

any help is much appreciated. thanks folks...

<?xml version="1.0" encoding="utf-8" ?>
<xs:tools xmlns:xsi="http://www.w3schools.com" xmlns:xs="http://
www.w3schools.com/2001/XMLSchema-instance" xs:schemaLocation="http://
www.w3schools.com tool.xsd">
<tool Name="tool1"
ToolTip="tool1"
ImageUrl="http://blah.com/images/tool1.png"
IsSelected="false"
Text="tool1"
Value="tool1" />
<tool Name="tool2"
ToolTip="tool2"
ImageUrl="http://blah.com/images/tool2.png"
IsSelected="false"
Text="tool2"
Value="tool2" />
</xs:tools >
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="tool" type="toolset" />
<xs:complexType name="toolset">
<xs:attribute name="Name" type="xs:string" use="required"/
>
<xs:attribute name="ToolTip" type="xs:string"
use="required"/>
<xs:attribute name="ImageUrl" type="xs:string"
use="required"/>
<xs:attribute name="IsSelected" type="xs:string"
use="required"/>
<xs:attribute name="Text" type="xs:string" use="required"/
>
<xs:attribute name="Value" type="xs:string" use="required"/
>
</xs:complexType>
</xs:schema>
Aug 25 '08 #1
5 1594
forest demon wrote:
i can't find any examples that address the way i have my elements and
attributes structured. i really don't want to have to redo my XML
file to conform to the way my .xsd validates! that just seems silly
and a cop-out to me. am i stubborn you ask? well, yeah!!! :-)
The XML editor in Visual Studio allows you to infer a schema from an XML
document so you might want to try that and use that schema as a starting
point. The xsd.exe tool in the .NET framework/Windows SDK can also do
that for you.

<xs:tools xmlns:xsi="http://www.w3schools.com" xmlns:xs="http://
www.w3schools.com/2001/XMLSchema-instance" xs:schemaLocation="http://
www.w3schools.com tool.xsd">
The use of prefixes and namespaces and attributes above is rather
confusing, the schemaLocation attribute is usually in the namespace
http://www.w3.org/2001/XMLSchema-instance and then the prefix xsi is
used for that namespace. So while the above markup is syntactically
correct I wonder why you put a schemaLocation attribute in the
www.w3schools.com namespace.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 25 '08 #2
On Aug 25, 4:51 am, Martin Honnen <mahotr...@yahoo.dewrote:
>
The XML editor in Visual Studio allows you to infer a schema from an XML
document so you might want to try that and use that schema as a starting
point. The xsd.exe tool in the .NET framework/Windows SDK can also do
that for you

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

that was definitely helpful and got me on the right track.

thanks martin, i appreciate your input.

-
fd
Aug 25 '08 #3
>The XML editor in Visual Studio allows you to infer a schema from an XML
>document so you might want to try that and use that schema as a starting
point.
How exactly do you do this? I haven't figured that one out yet.
>The xsd.exe tool in the .NET framework/Windows SDK can also do that for
you.
I always ended up with a dataset by the time I tried getting an xsd out of
an xml file with this way of doing it. sql server doesn't like the "dataset"
when I use the output as a column schema. The only way to get that to work
is to save the entire dataset to the column which isn't something I need to
do. Any ideas how to fix this?

Aug 25 '08 #4
Andy B wrote:
>The XML editor in Visual Studio allows you to infer a schema from an XML
document so you might want to try that and use that schema as a starting
point.
How exactly do you do this? I haven't figured that one out yet.
Add the XML file to the project and display it, then use the Xml menu ->
Create Schema menu entry or the button in the XML toolbar.
>The xsd.exe tool in the .NET framework/Windows SDK can also do that for
you.
I always ended up with a dataset by the time I tried getting an xsd out of
an xml file with this way of doing it. sql server doesn't like the "dataset"
when I use the output as a column schema. The only way to get that to work
is to save the entire dataset to the column which isn't something I need to
do. Any ideas how to fix this?
xsd.exe has various functions, if you want to infer a schema then the
command line is e.g.
xsd.exe file.xml

Make sure the file has the suffix .xml as the tool inferring a schema
depends on that. The inferred schema is then called file.xsd I think.
Documentation is here:
http://msdn.microsoft.com/en-us/libr...0s(VS.80).aspx

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 25 '08 #5
Got it. There is a project item in vs2008sp1 that is called XmlToSchema. It
is a wizard that lets you type in schemas, load them from fields and so on.
Then you press the ok button and it will do batch processing (or thats what
it looks like).
"Martin Honnen" <ma*******@yahoo.dewrote in message
news:eQ**************@TK2MSFTNGP05.phx.gbl...
Andy B wrote:
>>The XML editor in Visual Studio allows you to infer a schema from an XML
document so you might want to try that and use that schema as a starting
point.
How exactly do you do this? I haven't figured that one out yet.

Add the XML file to the project and display it, then use the Xml menu ->
Create Schema menu entry or the button in the XML toolbar.
>>The xsd.exe tool in the .NET framework/Windows SDK can also do that for
you.
I always ended up with a dataset by the time I tried getting an xsd out
of an xml file with this way of doing it. sql server doesn't like the
"dataset" when I use the output as a column schema. The only way to get
that to work is to save the entire dataset to the column which isn't
something I need to do. Any ideas how to fix this?

xsd.exe has various functions, if you want to infer a schema then the
command line is e.g.
xsd.exe file.xml

Make sure the file has the suffix .xml as the tool inferring a schema
depends on that. The inferred schema is then called file.xsd I think.
Documentation is here:
http://msdn.microsoft.com/en-us/libr...0s(VS.80).aspx

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Aug 26 '08 #6

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

Similar topics

14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
9
by: Pemburger | last post by:
From: pemburger@aol.com I've tried the W3C MarkUp Validation Service for the following web page: http://www.coverscript.com The report given by W3C shows 300 plus errors? I am not able to...
4
by: Nitin | last post by:
Hi I have created function to check date and time. at the time of execution, if date is left empty the function returns the error message but then the focus goes to next field. Next filed is for...
9
by: Nicole | last post by:
Okay, so I was working primarily in dreamweaver and the site looks very good in both IE (our customers primarily use this) and Firefox (my new 'thing'), but I ran it through the validator and...
1
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
4
by: Stone Chen | last post by:
Hello, I have form that uses javascript createElement to add additional input fields to it. However, my validating script will not process new input fields because it can only find the named...
1
by: Bambers | last post by:
hi all i have an contact us form with validation. the submit button make the script re-run and do the validation. the problem i have is; when all the validation is done and the user input is...
4
by: Melissa | last post by:
I currently have VBA written to export query results into an Excel file. That file is then formatted using the code below. The problem I'm having is that it keeps throwing Error 91 (Object...
1
by: lilbit02 | last post by:
Hi, I have a form that utilizes validation as most do via javascript. This form worked totaly fine until I needed to add a dynamic div now the validation doesn't work. It does work for the first...
6
by: smk17 | last post by:
I've spent the last few minutes searching for this question and I found an answer, but it wasn't quite what the client wanted. I have a simple online form where the user needs to fill out five...
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
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,...
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...
1
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...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.