Is your XmlObject something that you build on the fly, or is it actually
something that you
do parse? If you build your XmlObject on the fly, you will not get the
name.

If you actually parse it from a file, you can use XmlCursor to get the
name and you can get line number
using XmlError.


  public int getXMLValidationError(ArrayList validationErrors,
                                     ActionErrors errors) {
        Iterator iter = validationErrors.iterator();
        int i = 0;
        while (iter.hasNext() && i < MAX_XML_ERROR) {
            XmlError xmlError = (XmlError) iter.next();
            ActionError error = getError(xmlError);

            errors.add(ActionErrors.GLOBAL_MESSAGE, error);
            i++;
        }
        return i;
    }

    public ActionError getError(XmlError e) {
        String elementName = getElementNameError(e);
        String lineNumber = getLineNumberError(e);

        return (new ActionError("errors.xmlbean", elementName,
lineNumber, e.getMessage()));
    }

    public String getElementNameError(XmlError e) {
        String element = "Unknown";
        if (e != null) {
            XmlCursor cursor = e.getCursorLocation();
            cursor.toParent();

            QName qname = cursor.getName();
            if (qname != null) {
                element = qname.toString();
            }

        }
        return element;
    }

    public String getLineNumberError(XmlError e) {
        String lineNumber = "Unknown";
        if (e != null) {
            int line = e.getLine();
            if (line > 0) {
                lineNumber = (new Integer(line)).toString();
            }
        }
        return lineNumber;
    }





>>> [EMAIL PROTECTED] 3/3/2006 10:16:57 AM >>>
When i validate my XmlObject, i get a cryptic message as in: error:
cvc-maxLength-valid.1.1: string length (string) is greater than
maxLength
facet (9) for '2'

How do i get more information, as in, the specific element which is
invalid
so i can tell the user that: "hey, the: 'userName' element is too big"

when i try to use the other methods on the XmlError type i get:
error.getMessage()= error: cvc-maxLength-valid.1.1: string length
(string)
is greater than maxLength facet (9) for '2'
error.getSourceName()= null
error.getCursorLocation().xmlText()= <xml-fragment xmlns=""/>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to