Skip to main content

Problem in parsing a particular XML file.

4 replies [Last post]
cristianodp
Offline
Joined: 2007-10-05
Points: 0

Hello, I have an XML file like this:

...

PortaDelegata_PortaDiDominio_0000001_2007-10-05_12:26

...
PortaDelegata_PortaDiDominio_0000002_2007-10-05_12:26

...

---
As you can see there are 2 elements in which the values are really similar. In fact in the Schema we use they have to match the same regular expression; here's the extract from my schema.

I can CORRECTLY validate this expression using this code:

public void validate (String doc, String schema) throws SAXParseException, SAXException
{
try
{
SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );

Schema schemaXSD = schemaFactory.newSchema( new File ( schema ) );

Validator validator = schemaXSD.newValidator();

DocumentBuilderFactory.newInstance().newDocumentBuilder();

ByteArrayInputStream baisDoc = new ByteArrayInputStream(doc.getBytes());

Document document = parser.parse(baisDoc);

validator.validate( new DOMSource( document ) );

...

And, in case the validation fails, I correctly gain a SAXParseException.
The problem is that I can't understand if, in this case, the error is in the "Collaborazione" element or in the "Identificatore" element, because I get the following detailed message from the Exception:

"cvc-pattern-valid: Value '' is not facet-valid with respect to pattern '[\w]+_[\w]+_\d{7}_\d{4}\-\d{2}\-\d{2}_\d{2}:\d{2}' for type 'IdentificatoreType'."

How can I get more detailed informations about this error?

Thanks everybody,
Cris

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joehw
Offline
Joined: 2004-12-15
Points: 0

Hi Cris,

This may be a bug in Jaxp. I mean that "value" in the error message should not have been empty. Could you create a workable testcase and file a bug report in JAXP issue tracker?

Meanwhile, for your debugging purpose, you may consider removing one of the elements to isolate the problem.

Thanks.

joehw
Offline
Joined: 2004-12-15
Points: 0

I spoke too soon :)

I tried your code with your xml file but made one of the elements invalid, e.g. by taking out a 0, I got a proper error message such as this:
cvc-pattern-valid: Value 'PortaDelegata_PortaDiDominio_000001_2007-10-05_12:26' is not facet-valid with respect to pattern '[\w]+_[\w]+_\d{7}_\d{4}\-\d{2}\-\d{2}_\d{2}:\d{2}' for type 'IdentificatoreType'.

I'm not sure why the error message you got had an empty value. Could you make a testcase that would re-produce the problem? Thanks.

cristianodp
Offline
Joined: 2007-10-05
Points: 0

With a different XML I got this error message:

"org.xml.sax.SAXParseException: cvc-pattern-valid: Value 'PortaDelegata_PortaDiDominio_333_2007-10-08_12:56' is not facet-valid with respect to pattern '[\w]+_[\w]+_\d{7}_\d{4}\-\d{2}\-\d{2}_\d{2}:\d{2}' for type 'IdentificatoreType'."

In my XML I sent these 2 strings:

PortaDelegata_PortaDiDominio_333_2007-10-08_12:56

PortaDelegata_PortaDiDominio_0000001_2007-10-08_12:56

Where the 1st one, , doesn't match the pattern, therefore it generates the parsing error. My main problem is still the same: from the error message I get, I can NOT know which of the 2 elements contains the wrong string. How can I understand if the problem is in the element or in the one?

Is there a way to know this?
Thanks,
Cristiano

joehw
Offline
Joined: 2004-12-15
Points: 0

Right, I agree that it would be helpful if the error report contained the name of the element. Without that, you could still search your xml with the value in the error message to find out in which element the problem is.