Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting all errors during xml validation???

Status
Not open for further replies.

Jam1

Programmer
Nov 4, 2002
6
US
I am parsing (validating) an xml document against a schema file using MSXML4.0 and ASP.
Is it possible to capture all the errors that the xml doc has against the schema?
I tried doing "on error resume next" but still it brings only the first error and halts
there.
could someone help me out with ideas?
 
The ParseError object will only show you the first error. Sorry.

Chip H.
 
Oh ... Ok.
So there is no way we can list all the errors in the xml document to the users!!!
my users are uploading the document and if they had made 10 errors at 10 different places in the doc, I wanted to list them for users so that its easy to make changes at one go rather than giving the errors one at a time.

Is there any way to accomplish this?
atleast in other methods like SAX or anything else.
Thanks a lot Chip.
 
You could always run two copies, the original and another variable with the one you are running through. Then as you are attempting to validate, when it kicks out an error, save this in an array, remove the parent of the offender, and re-validate. Continue until you have a clean document, then return the erros to the person with the note that one or more of the later errors could be in fact correct, except that sometimes early errors cause errors later in the document due to formatting and end tag placement.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Yes. This was somewhat similar to one of my couple of options but had some worries. Since I am new to the technology ... I was unsure of it.

Option1.. YOUR METHOD.
My XML doc is validated against a schema. So
I got the method of appending the error mesg string to output to the user but the parseError object does not help in locating the node that has an error. So if one of the child elements has an error.. I need to locate the child and remove the complete set of child element and the corresponding parent node so that it conforms with the schema.
Could you show me a code snippet of how this is possible?
By complete set, I mean from <Info> to </Info>(all child elements included>:
<data>
<Info>
<name> XXX </name>
<age> 21 </age>
<gender> Male </gender>
</Info>
<Info>
<name> XXX </name>
<age> 21 </age>
<gender> Male </gender>
</Info>
...
...
...
</data>


Option2...
I had this idea of reading the xml document for every one complete set of nodes along with parent node, load into the DOM using loadXML() (in a schema cache) and validate it.
If this has errors, I append a error string else get the next set and go on.
But, I understand DOM uses more memory...would this create memory issues?
moreover, how this idea looks like for 1000 sets of <Info> ... </Info>?
the validation has to be in a loop doing 1000 times.
This is just an idea... I dont have a working proof.


Could you please give me your opinion on this
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top