7 Replies Latest reply on Feb 25, 2009 1:00 PM by rhaddan

    More XmlValidate Questions

    robs67 Level 1
      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?
        • 1. Re: More XmlValidate Questions
          robs67 Level 1
          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.
          • 2. Re: More XmlValidate Questions
            rhaddan Level 1
            Did you ever get an answer to this? I'm looking to do the same thing.
            • 3. Re: More XmlValidate Questions
              Level 1
              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
              • 4. Re: More XmlValidate Questions
                rhaddan Level 1
                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.
                • 5. Re: More XmlValidate Questions
                  Level 7
                  > 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
                  • 6. Re: More XmlValidate Questions
                    rhaddan Level 1
                    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!!
                    • 7. Re: More XmlValidate Questions
                      rhaddan Level 1
                      Here's a more detailed outline of how this worked out. Enjoy!

                      http://cfgov.blogspot.com/2009/02/create-usable-error-messages-with.html