Question

Using the jericho api, can I validate a given html tag like <input type="test" .....>? I was unable to find an api in jericho that would do so. Is there a way where I could do that using jericho only? I dont want to tidy or Sanitise the html tag. I just want to check for its validity.

No correct solution

OTHER TIPS

jericho api will log all the validations telling you all your flaws and gaps in the constructed html you are validating. It does its own version of tag tidying but also logs that information of it's version of the logger.

Let's try to print what jericho thinks about your html tag:

PrintWriter writer = new PrintWriter(System.out);
WriterLogger myLogger = new WriterLogger(writer);
myLogger.setInfoEnabled(true);

Source source = new Source("<input type=\"test\" .....>");
source.setLogger(myLogger);

try {
    source.getSourceFormatter().writeTo(writer);
} catch (Exception e) {
    e.printStackTrace();
}

Output which I get is:

ERROR: StartTag input at (r1,c1,p0) contains attribute name with invalid first character at position (r1,c20,p19)
<input type="test" .....>

This log entry looks to be parseable and can be used in more than one way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top