Reputation: 932
I'm trying to use the jStyleParser library ( part of the CSSBox project) to analyze the css of a generic web page and bind all the css information to the DOM of that page. My goal is, given a web page, to have a DOM tree such that, for each node, I can get all the css informations realted to tha node.
This is (part of) my code:
System.out.println("Analizing "+Mylocalfile.getAbsolutePath());
StyleSheet ss = CSSFactory.parse(Mylocalfile.getAbsolutePath(), "UTF-8");
if (ss.isEmpty()) System.out.println("StyleSheet is void");
The parse method seem to be unable to parse the file: the StyleSheet ss is infact void.
Do you know why?
Upvotes: 0
Views: 808
Reputation: 888
Your code is correct as long as MyLocalFile points to a CSS style sheet (*.css). In that case, you should obtain the parsed style sheet in ss but it is not bound to any DOM. If you still obtain an empty style sheet, there might be a bug in the CSS code or even in the parser. In that case, I recommend to report this to the jStyleParser forum at SourceForge.
If you want to assign the style definitions to a DOM (MyLocalFile points to an HTML file), you should use the assignDOM method as described in the jStyleParser manual. In that case, you should parse the HTML document with a DOM parser and use the assignDOM method to automatically retrieve the referenced style sheets and compute the element styles. You may find an example in src/test/DOMAssign.java in the jStyleParser source package.
Upvotes: 1