Actualmente estoy usando mi XSD para validar mi xml. Esta parte funciona bien, mi problema es que quiero obtener el elemento de la etiqueta/valor que no es válido.Cómo obtener el elemento y el archivo xml no válido con xsd Validación fallida
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
XMLStreamReader reader = null;
SchemaFactory factory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(xsdschemalocation);
Validator validator = schema.newValidator();
try
{
reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(new StringReader(xml)));
} catch (XMLStreamException ex)
{
LogController.getLogger().logSEVERE("Unable to create the streamreader from the xml source", ex.getLocalizedMessage());
return false;
}
try
{
validator.validate(new StAXSource(reader));
}
catch (IOException ex)
{
LogController.getLogger().logSEVERE("IOException in the validatation has been caused as the reader has become null", ex.getLocalizedMessage());
return false;
}
catch(SAXException saxe)
{
LogController.getLogger().logWARNING("Their is a validation error with the xml", saxe.getLocalizedMessage());
//*****HERE I WANT THE TAG THAT HAS THE ERROR
ClientCommunication.ErrorMessageForClient(VALIDATION_ERROR, socket);
CloseClientConnection();
return;
}
La idea que tenía, que no es práctico es buscar en el mensaje de la palabra "tipo" o "etiqueta final" y obtener el valor después de que, sin embargo sé que esto no va a ser bueno ¡práctica! Esto me resulta frustrante, ya que puedo ver la etiqueta que no es válida pero no puedo obtenerla.
Éstos son algunos ejemplos del elemento Quiero
1. Message: Element type "first" must be followed by either attribute specifications, ">" or "/>".
2. javax.xml.stream.XMLStreamException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 353; cvc-pattern-valid: Value '079e989989' is not facet-valid with respect to pattern '([0-9])+' for type 'phoneNumber'.
3. Message: The element type "firstLine" must be terminated by the matching end-tag "</firstLine>".
¿Hay alguna forma en que pueda obtener el valor no válido también en forma de cadena? –
Exactamente lo que quería – pup784