Mike Davis wrote:
I want to parse XML attachments to a page and display the data in a table or list on the page. Does this functionality exist? Just checking before I write my own code. So you have attachments which are XML files and you want to parse them and display their content in a wiki table ? If so, I'd suggest you use the {{groovy}} macro and use the groovy xml slurper to do the work. You should be able to write this in less than 10 lines :) http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlSlurper
Thanks -Vincent Thanks, got that up and running in only a few minutes! Now I'd like a way to have the user click on one level of the xml hierarchy I display and have it expand to show the children of that section (I have the hierarchy iteration code, just not the "gui" code). Something graphically like a macro error (the one that says "Failed to execute macro: groovy") and then you click to expand and view the content.
http://code.xwiki.org/xwiki/bin/view/Snippets/ShowHideDIVSnippet
Guillaume
Ok, I have that code working (ShowHidDIV) in a velocity macro with {{html}} tags around the div. Unfortunately, when I pass the xmlslurper object to a velocity macro, I can no longer access fields of the object, it looks like it's all being converted to a big string. My code:
I would approach this problem by using groovy only. When your velocity or groovy executes, it's output is parsed as XWiki syntax so you can do this in the groovy macro. println("{{html}}"); // Remember to escape " marks. println("<div onclick=\"toggleClass($('REG'), 'hidden')\">"); println("Show/Hide"); println("</div>"); pritnln("<div id=\"REG\" class=\"hidden\">"); // Is getField() what you want? println(allReg.getField()); println("</div>"); println("{{/html}}"); Your method is sound and I'm sure it could be made to work, but I would opt to use one script language in order to minimize the code complexity and fragility. Caleb
{{groovy}}
xmlFile = new String(doc.getAttachment("file.xml").content) def slurp = new XmlSlurper().parseText(xmlFile) def allReg = slurp.Register xcontext.put("allReg",allReg)
{{/groovy}}
{{velocity}} #set($allReg=$xcontext.get("allReg"))
{{html}} <div onclick="toggleClass($('REG'), 'hidden')"> Show/Hide </div> <div id="REG" class="hidden> $allReg.field </div> {{/html}} {{/velocity}}
But like I said, I can't access the fields of allReg in the velocity script: $allReg.field just returns the whole string from the slurper. So I need a way to either embed html in the groovy code with access to the groovy variables, or a way to correctly pass a slurper object using xcontext.
Thanks,
-Mike
_________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/210850553/direct/01/ _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users