473,473 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Validating a XML input

Hi again, folks.

i'm developing a windows application that gets data from an Mysql
database through PHP server-side scripts. I'm not totally familiar
with Requests and XML on .Net 2.0.
I'll load these sort of data - simply generated by the phps - into a
dataset and i want to validate, before, if the response from server
isn't anything other than an valid XML structure, to be able to catch
eventual server-side errors.
How this could be done? Load the data into a xml object and catch
parse errors?

Thanks for any appointments

Thiago
Jun 27 '08 #1
7 1203
Thiago Macedo wrote:
i'm developing a windows application that gets data from an Mysql
database through PHP server-side scripts. I'm not totally familiar
with Requests and XML on .Net 2.0.
I'll load these sort of data - simply generated by the phps - into a
dataset and i want to validate, before, if the response from server
isn't anything other than an valid XML structure, to be able to catch
eventual server-side errors.
How this could be done? Load the data into a xml object and catch
parse errors?
I am not sure where XML comes in if PHP and MySQL generate data but
assuming you get XML and want to check it is well-formed then simply
pull it through an XmlReader:

Using reader As XmlReader = XmlReader.Create("file.xml")
Try
While reader.Read()
End While
Catch ex As XmlException
' handle error that XML is not well-formed
End Try
End Using

If you have an W3C XML Schema for the XML then you can also validate it
by using XmlReaderSettings where you set the ValidationType to Schema,
add any schemas you have to the Schemas property and set up a
ValidationEventHandler. See
http://msdn.microsoft.com/en-us/libr...b8(VS.80).aspx

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
Thiago,

\\\
Try
yourDataSet.ReadXML(path (or I thought just the serialized xml file)
Catch
'hello there is an error
End Try
///

http://msdn.microsoft.com/en-us/libr...ml(VS.71).aspx

(Don't become afraid for the samples, the above works in all normal
situations).

Cor

"Thiago Macedo" <th**********@gmail.comschreef in bericht
news:06**********************************@a1g2000h sb.googlegroups.com...
Hi again, folks.

i'm developing a windows application that gets data from an Mysql
database through PHP server-side scripts. I'm not totally familiar
with Requests and XML on .Net 2.0.
I'll load these sort of data - simply generated by the phps - into a
dataset and i want to validate, before, if the response from server
isn't anything other than an valid XML structure, to be able to catch
eventual server-side errors.
How this could be done? Load the data into a xml object and catch
parse errors?

Thanks for any appointments

Thiago
Jun 27 '08 #3
On May 1, 8:52 am, Martin Honnen <mahotr...@yahoo.dewrote:
Thiago Macedo wrote:
i'm developing a windows application that gets data from an Mysql
database through PHP server-side scripts. I'm not totally familiar
with Requests and XML on .Net 2.0.
I'll load these sort of data - simply generated by the phps - into a
dataset and i want to validate, before, if the response from server
isn't anything other than an valid XML structure, to be able to catch
eventual server-side errors.
How this could be done? Load the data into a xml object and catch
parse errors?

I am not sure where XML comes in if PHP and MySQL generate data but
assuming you get XML and want to check it is well-formed then simply
pull it through an XmlReader:

Using reader As XmlReader = XmlReader.Create("file.xml")
Try
While reader.Read()
End While
Catch ex As XmlException
' handle error that XML is not well-formed
End Try
End Using

If you have an W3C XML Schema for the XML then you can also validate it
by using XmlReaderSettings where you set the ValidationType to Schema,
add any schemas you have to the Schemas property and set up a
ValidationEventHandler. Seehttp://msdn.microsoft.com/en-us/library/hdf992b8(VS.80).aspx

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
I'm converting the mysql data manualy by PHP script. So I have a
simple well-formed XML, with no schemas.
Ok, i can get the xml exception, but after read it (xmlreader) i lost
the stream and can't load the data into the dataset.
Another approaches? Am I missing something?

thank you for your help

Thiago
Jun 27 '08 #4
On May 1, 9:58 am, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
Thiago,

\\\
Try
yourDataSet.ReadXML(path (or I thought just the serialized xml file)
Catch
'hello there is an error
End Try
///

http://msdn.microsoft.com/en-us/libr...aset.readxml(V...

(Don't become afraid for the samples, the above works in all normal
situations).

Cor

"Thiago Macedo" <thiago.ch...@gmail.comschreef in berichtnews:06**********************************@a 1g2000hsb.googlegroups.com...
Hi again, folks.
i'm developing a windows application that gets data from an Mysql
database through PHP server-side scripts. I'm not totally familiar
with Requests and XML on .Net 2.0.
I'll load these sort of data - simply generated by the phps - into a
dataset and i want to validate, before, if the response from server
isn't anything other than an valid XML structure, to be able to catch
eventual server-side errors.
How this could be done? Load the data into a xml object and catch
parse errors?
Thanks for any appointments
Thiago
Hi Cor, just see your message.

Yes, that's not good samples.. but i already can load the data. My
problem is on handling the server-side errors, which is generated by
the PHPs (i'm calling them 'services').
I call them with an HttpWebRequest and input the data into the DataSet
with it response. But before i need to check if there aren't any php
messages, and in this case no xml would be generated, therefore the
"catch" statement
Jun 27 '08 #5
Thiago Macedo wrote:
I'm converting the mysql data manualy by PHP script. So I have a
simple well-formed XML, with no schemas.
Ok, i can get the xml exception, but after read it (xmlreader) i lost
the stream and can't load the data into the dataset.
Another approaches? Am I missing something?
If you want to pass the XmlReader to another method like the ReadXml
method of a DataSet then you don't need the while loop with the Read
call that I posted. If you get an XmlException then the markup is not
well-formed, I thought that is what you want to check when you asked for
"validating XML input".
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #6
On May 1, 1:18 pm, Martin Honnen <mahotr...@yahoo.dewrote:
Thiago Macedo wrote:
I'm converting the mysql data manualy by PHP script. So I have a
simple well-formed XML, with no schemas.
Ok, i can get the xml exception, but after read it (xmlreader) i lost
the stream and can't load the data into the dataset.
Another approaches? Am I missing something?

If you want to pass the XmlReader to another method like the ReadXml
method of a DataSet then you don't need the while loop with the Read
call that I posted. If you get an XmlException then the markup is not
well-formed, I thought that is what you want to check when you asked for
"validating XML input".

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Yes, you get my point. But it only "validates" the input on the read
method, and the object is foward-only, so can't be read by ReadXml.
I may be missing something on the XmlReader class.. think this could
be done.

Thiago
Jun 27 '08 #7
Thiago Macedo wrote:
Yes, you get my point. But it only "validates" the input on the read
method, and the object is foward-only, so can't be read by ReadXml.
I may be missing something on the XmlReader class.. think this could
be done.
You have the choice: if you only want to check for well-formedness then
use an XmlReader with a while loop pulling in all nodes until you get an
exception or read through without getting an exception. If you
additionally want to load the XML into a DataSet then you need to use a
second reader. Or you do not set up an XmlReader at all and directly
load into the DataSet, that should nevertheless report any problems with
the XML.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #8

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

Similar topics

5
by: The Plankmeister | last post by:
Hi... What's the best method of validating input characters? I would like to prevent users submitting exotic characters (such as those acquired on Windows Systems by pressing ALT+) and thought...
3
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it...
6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
2
by: bildad | last post by:
The following 'book example' of validating input seems to be incomplete. Since it is a beginner's book it may be intentional for simplicity. But I would like to know how to make this program work...
0
by: Bradley Bossard via DotNetMonster.com | last post by:
I am having an issue with the .NET framework (or C#) and validating events. I have implemented several validating event handlers for textboxes on a form. When I run the app, the form works...
9
by: chuck | last post by:
I need some help with validating user input. I am writing a C computer program for an intro to C course. Here is the situation. I am creating an application that will do currency conversions. ...
5
by: Kavya | last post by:
I saw these two ways for validating input First Way -------------- #include <iostream> #include <limits> using namespace std; int main() {
3
by: William Gill | last post by:
I have decided that Since I have to update the processing on many of my forms, I'm going to start them all over from scratch. Before I begin I thought I'd solicit comments on using the PHP regex...
6
by: Richard | last post by:
I'm validating a date and time string which must be EXACTLY of the format yy-mm-dd hh:mm:ss and extracting the six numeric values using sscanf. I'm using the format string "%2u-%2u-%2u...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
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 ...

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.