2

How I can get some information (column, line, message) at this code?

String xhtml = "<html><body><p>Hello, world!<p></body></html>";
ValidationResponse response = new ValidatorBuilder().html().validate(xhtml);
if (!response.valid()) 
{
    Set<Defect> errors = response.errors();
    //... what write at this place?
    System.out.println(errors[0].column() + " " + errors[0].source());
}

I tried to write as:

String xhtml = "<html><body><p>Hello, world!<p></body></html>";
ValidationResponse response = new ValidatorBuilder().html().validate(xhtml);
 if (!response.valid()) 
 {
     Set<Defect> errors = response.errors();
     Defect[] errorsArray = (Defect[]) errors.toArray();
     System.out.println(errorsArray[0].column() + " " + errorsArray[0].source());
 }

But get exception:

Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lcom.rexsl.w3c.Defect; at HTMLValidator.main(HTMLValidator.java:17)

4

1 に答える 1