Get components that are inside an xhtml file

3

In a facelets (xhtml) source code of primefaces, I want to extract all <p:inputText> tags. After that, I want to get the label attribute. How could he accomplish this? Remembering that the components have different filled-in values, and I can put other primefaces tags as outputlabel or div .

    
asked by anonymous 13.02.2014 / 15:31

1 answer

2

You need a parser. While JDK has the DocumentParser , it is legacy and tied to the Swing APIs.

My recommendation would be Jsoup

// Trate exceções no código real
File input = new File("/tmp/input.xhtml");
Document doc = Jsoup.parse(input, "UTF-8");
Elements labels = doc.select("p|inputText[label]");
// todos os inputs que possuem um label
for (Element label : labels) {
   String sLabel = label.attr("label"); 
   System.out.println("Label: " + sLabel);
}

I'm assuming you're going to extract the labels directly from the Facelets code, but if you need to extract from the generated html, just adapt the code accordingly.

    
13.02.2014 / 15:57