|
Re: Generating XML with namespace?: msg#00145lang.groovy.user
Michael, Sorry for the slow response. As far as I can tell, it's not possible to generate the XML you show below using MarkupBuilder. Here's my closest attempt: ---begin--- import groovy.xml.DOMBuilder; import groovy.xml.Namespace; import org.apache.xalan.serialize.SerializerToXML; builder = DOMBuilder.newInstance(); namespace = new Namespace(builder, "http://www.example.com/mynamespace", "my"); output = namespace.root(xmlns:["my":"http://www.example.com/mynamespace"]) { child(); } printer = new SerializerToXML(); printer.init(System.out, null); printer.serialize(output); println ""; ---end--- This prints out: ---begin--- <?xml version="1.0" encoding="UTF-8"?> <my:root my="http://www.example.com/mynamespace"><my:child/></my:root> ---end--- I would have expected the 'xmlns' attribute of the root call to add what you wanted as an attribute, but it doesn't. Not sure why not. It also seems like the namespace builder puts all tags it generates into the namespace, so maybe there's a method like "widget()" in SwingBuilder that will let you add in an element outside of the namespace. The best places to look are <http://cvs.groovy.codehaus.org/viewrep/groovy/groovy-core/src/main/groovy/xml> and <http://cvs.groovy.codehaus.org/groovy/groovy-core/src/test/groovy/xml/> for more leads. It looks to me like <http://cvs.groovy.codehaus.org/viewrep/groovy/groovy-core/src/test/groovy/xml/NamespaceDOMTest.groovy?r=1.1> would be the best file to examine. I was trying to get your example to work without the XSD element, but maybe that's wrong-headed. Sorry I couldn't help more. Marc Hedlund e: marc at precipice dot org On Thu, 14 Oct 2004, Michael Schuerig wrote: > > I've seen the recent message regarding MarkupBuilders, still I don't > quite get it. I want to generate (textual) XML with a namespace. > Something like > > <my:root xmlns:my="http://www.example.com/mynamespace"> > <child/> > ... > </my:root> > > > > I've had a look at <http://groovy.codehaus.org/GroovyMarkup> and > <http://wiki.codehaus.org/groovy/TreeBasedSyntax>, but they were more > confusing than helpful to me as they presuppose too much that I don't > yet understand. > > Michael > > -- > Michael Schuerig The usual excuse for our most unspeakable > mailto:michael-q5aiKMLteq4b1SvskN2V4Q@xxxxxxxxxxxxxxxx public acts is > that they are necessary. > http://www.schuerig.de/michael/ --Judith N. Shklar >
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | TemplateServlet does not work with groovy-1.0-beta-7, phkim-Yd8/yUic+sk+MW+wcPHoAA |
|---|---|
| Next by Date: | RE: TemplateEngine doesn't work on 1.0 beta 7, Laforge Guillaume |
| Previous by Thread: | Generating XML with namespace?, Michael Schuerig |
| Next by Thread: | calling methods that take an array or list of interfaces, Randy Thornton |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |