Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

More XmlValidate Questions

Guest
Nov 12, 2008 Nov 12, 2008
This may be a really stupid question, but to what do the numbers returned in the structure refer? For example:
[Error] :13:32: cvc-length-valid: Value 'x' with length = '1' is not facet-valid with respect to length '8' for type 'null'.

What does 13:32 refer to?

Also, and perhaps along the line of the above, how can I output the exact line or node that is causing the problem?
TOPICS
Advanced techniques
800
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 12, 2008 Nov 12, 2008
Ok, so I am a bit slow on the uptake. I figured out those are line numbers and positions.

So here's another related question. Does anyone know how I can look for that line number and pull the string on that line out of the xml file? I'd like to show where/what the error is and perhaps translate the error code into english while I'm at it.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 23, 2009 Feb 23, 2009
Did you ever get an answer to this? I'm looking to do the same thing.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 23, 2009 Feb 23, 2009
Doing a Google search on "cvc-length-valid", it seems that this is probably the sort of exception Xerces raises when an XSD validation fails.

You might want to read the Xerces docs for more info.

Or you might want to settle for outputting an error message along the lines of "that XML you gave me was bung", and leave it at that.

As for working out line numbers, the lines are delimited by chr(10) and/or chr(13), so treat the XML as a list delimited by those characters at pull out the nth line. Then the character position is easy enough to extract from the line itself.

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 24, 2009 Feb 24, 2009
In my case, I need to tell the user exactly where the error occurred. I'm converting a CSV file with thousands of rows into a Coldfusion XML object. Unfortunately, the lines are not delimited using this method. You get two lines in your XML document: the XML declaration on line 1 and the rest on line 2.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 24, 2009 Feb 24, 2009
> In my case, I need to tell the user exactly where the error occurred. I'm
> converting a CSV file with thousands of rows into a Coldfusion XML object.

I'd approach it differently (given the error you're getting is no help to
you). Validate the data before you put it into the XML string. If you've
got an XSD that says "this attribute needs to be this sort of value", then
you can do the same validation as you populate the XML.

If all your XML is in one long line without CR/LF characters in it, then
the error message reporting line:col is not a reference to that data. It
might be a reference to the XSD file?

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2009 Feb 25, 2009
I got it... thanks Adam for both of your posts. They got my wheels turning. Each item in my XML object (element name "item") contains several children; I'm interested in returning all of the children for that item.

After doing my conversion, I get an XML object called myXmlObj. I immediately take that XML object and do:

<cfset myXmlObj = Replace(ToString(myXmlObj),"<item>",Chr(10) & "<item>", "all") />

which gives me a delimited list that matches the line numbers not only in the original CSV but also in the XmlValidate error results.

When I get a validation error (XmlValidate results stored in "myResults"), I loop through the returned errors and parse the error message as a list (using : as a delimeter) to get the line number using ListGetAt().

<cfset errorLine = ListGetAt(myResults.errors ,2,":") />

I now have a reference to the XML item number and return it and it's children from myXmlObj using:

<cfset xmlSnip = XmlParse(ListGetAt(myXmlObj,errorLine,Chr(10))) />

Now I can loop through the xmlSnip XML object, put the results in a table, and show the user exactly where the error occurred in the context of the entire record.

I will document this better and post to a blog entry. When I do, I'll post a link here with a better example of how it works.

Thanks again for the assist!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2009 Feb 25, 2009
LATEST
Here's a more detailed outline of how this worked out. Enjoy!

http://cfgov.blogspot.com/2009/02/create-usable-error-messages-with.html
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources