Connecting Tech Pros Worldwide Help | Site Map

Help needed with .xsd validation

  #1  
Old August 25th, 2008, 04:15 AM
forest demon
Guest
 
Posts: n/a
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"/
Quote:
>
<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"/
Quote:
>
<xs:attribute name="Value" type="xs:string" use="required"/
Quote:
>
</xs:complexType>
</xs:schema>
  #2  
Old August 25th, 2008, 11:55 AM
Martin Honnen
Guest
 
Posts: n/a

re: Help needed with .xsd validation


forest demon wrote:
Quote:
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.

Quote:
<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/
  #3  
Old August 25th, 2008, 04:15 PM
forest demon
Guest
 
Posts: n/a

re: Help needed with .xsd validation


On Aug 25, 4:51 am, Martin Honnen <mahotr...@yahoo.dewrote:
Quote:
>
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
  #4  
Old August 25th, 2008, 04:15 PM
Andy B
Guest
 
Posts: n/a

re: Help needed with .xsd validation


>The XML editor in Visual Studio allows you to infer a schema from an XML
Quote:
>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.
Quote:
>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?



  #5  
Old August 25th, 2008, 04:35 PM
Martin Honnen
Guest
 
Posts: n/a

re: Help needed with .xsd validation


Andy B wrote:
Quote:
Quote:
>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.
Quote:
Quote:
>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/
  #6  
Old August 26th, 2008, 02:55 AM
Andy B
Guest
 
Posts: n/a

re: Help needed with .xsd validation


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" <mahotrash@yahoo.dewrote in message
news:eQecqdsBJHA.4724@TK2MSFTNGP05.phx.gbl...
Quote:
Andy B wrote:
Quote:
Quote:
>>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.
>
Quote:
Quote:
>>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/

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent Help Needed With XSD, HELP PLEASE!!!! ah123 answers 1 October 5th, 2007 06:45 PM
Download the JAVA , .NET and SQL Server interview with answers Jobs answers 2 September 26th, 2006 02:25 PM
How can I validate an XML document with C#? Doru Roman answers 5 March 29th, 2006 10:45 PM
XSD and XMLDocument Dilemma - please help Modica82 answers 0 November 23rd, 2005 05:43 AM