> > > > 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:

{{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

Reply via email to