
08-11-10, 09:54 AM
|
|
New Member
|
|
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
RegEx, XSD and DataSet
i have a XSD file that includes the simple types
and the element
however when i load the xsd into a dataset using
and then feed in the xml
it lets both the 09 telephone number and the bad email through
what am i missing?
|

08-12-10, 04:07 AM
|
 |
Code Master
|
|
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
|
|
Hi there,
Try this code. I use it in my Apps and Websites and it never really fails. Note that I translated it from C# to VB.Net, but tested it in a Web Application in VB.Net and it was working. The Server.Mappath you can replace with an equivalent or just put full file path in the string part.
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
|
|
The Following User Says Thank You to Yeroon For This Useful Post:
|
|

08-12-10, 04:13 AM
|
 |
Newbie Coder
|
|
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
thanks personally i perfer C# but people i work for are still using VB6 so not a chance of getting them onto a C based syntax. shifting to .net was a breakthrough
thats validating using a XML schema object so i take it that the part i'm missing is that the DataSet's XML schema implementation doesn't support the more advanced validation aspects that can be used in an xsd?
__________________
Definition of a Beginner, Someone who doesn't know the rules.
Definition of an Expert, Someone who knows when to ignore the rules.
|

08-12-10, 05:01 AM
|
 |
Code Master
|
|
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
|
|
Hi,
Yea you need to load the XSD as an XmlSchema. The validation mechanics in .Net require the XmlDocument to be validated versus that XmlSchema. If you want to use datasets, you will have to iterate through the rows and validate yourself.
Your ds.ReadXmlSchema(fi.OpenRead()) only reads it into a dataset, thus it contains data. No longer a schema to validate against.
You could use the Merge method of DataSet. If in the code below the dataset Result is not Nothing (null), then there were differences. Basically your create a DataSet from the XSD and your XML. Then try to merge both into a new DataSet (ds3). After you load the XSD, you accept changes, so the structure gets set. Then you merge the XML dataset. If it can't merge it, the GetChanges will put a dataset in Result.
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Last edited by Yeroon; 08-12-10 at 05:05 AM.
|

08-12-10, 05:04 AM
|
 |
Newbie Coder
|
|
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
thanks for confirming that
__________________
Definition of a Beginner, Someone who doesn't know the rules.
Definition of an Expert, Someone who knows when to ignore the rules.
|

08-12-10, 05:07 AM
|
 |
Code Master
|
|
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
|
|
Hi,
Was just thinking the dataset merge method will only show you structural errors. It will not validate content if the structure is correct.
So my first answer is the way to go I think.
/Yeroon
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
|

08-12-10, 05:22 AM
|
 |
Newbie Coder
|
|
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
i'll have to rebuild one of their existing systems to do that with the schema object and if i do i'd probably leave the dataset where it is (if it ain't broke don't fix it) but validate the XML prior to the code feeding into it
__________________
Definition of a Beginner, Someone who doesn't know the rules.
Definition of an Expert, Someone who knows when to ignore the rules.
|

08-12-10, 05:55 AM
|
 |
Newbie Coder
|
|
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
just to give you the back ground, people i work for have a webservice where data is fed into it and it then parses it through a dataset and dumps it into a database. the interesting thing is that the dump depends is dependent on which schema.is used, so the validation can't be hard coded. currently the data is validated in the DB but because of server load they want to do this before it hits the database and but with out changing the web service. hence why i was looking into if they schema could validate it
__________________
Definition of a Beginner, Someone who doesn't know the rules.
Definition of an Expert, Someone who knows when to ignore the rules.
|

08-12-10, 06:52 AM
|
 |
Code Master
|
|
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
|
|
Well the call to the webservice is a XML call. So you could validate it before trnasforming it to a dataset. I am looking through one of my projects now where i basically did the same thing. Will get back to you.
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
|

08-12-10, 07:10 AM
|
 |
Code Master
|
|
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
|
|
I was just thinking. You probably have a collection of XSD's for the datasets. Can't you put the incoming XML through all these schema's to see if one matches. If none match obviously they have a problem with the input, but when you do manage to validate one, you know what dataset is to be used.
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|