markupbuilder

Groovy markupBuilder updating parent node

十年热恋 提交于 2019-12-14 03:59:21
问题 I'm building xml using MarkupBuilder and wonder how can I update a parent attribute when creating a child node. Assuming the number of child elements cannot be calculated when building the parent element. def writer = new StringWriter() def xml = new MarkupBuilder(writer) xml.parent(totalDuration: 'should be: some of all child duration') { child(duration: '1') child(duration: '2') ... } Is there an elegant way of accessing the parent node from a child node? Thanks Tal 回答1: Is there an elegant

How to add
after text in XML element in Groovy MarkupBuilder

半世苍凉 提交于 2019-12-12 01:58:01
问题 Basically we are changing the datasource XML for an InDesign project the way the old. We don't want to change the InDesign so I have to adapt the new XML from the new datasource (a SOAP webservice via Mule ESB). I use groovy to convert said XML, all was going until I faced this issue. The old XML in InDesign only works with this special character added to after every text: . Here's an example of a working XML : <?xml version='1.0' encoding='UTF-8'?> <w_import_saisie_web><w_evenement><w

groovy-wslite markupbuilder weired namespacing issue in soap-client

为君一笑 提交于 2019-12-11 13:15:08
问题 please help, i have a problem with the markupbuilder with groovy. WORKING SOAP REQUEST against endpoint MYENDPOINT and the action MYACTION: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:SPECIAL"> <soapenv:Header> <urn:xsdInfo> <urn:schemaLocation>SCHEMALOCATION</urn:schemaLocation> </urn:xsdInfo> <urn:category>Data Tables</urn:category> <urn:userInfo> <urn:sessionId>XXXXX</urn:sessionId> </urn:userInfo> </soapenv:Header> <soapenv:Body> <urn:add>

Creating <use> tag with StreamingMarkupBuilder

自古美人都是妖i 提交于 2019-12-11 03:48:18
问题 I am using StreamingMarkupBuilder to produce XML and I need to have a tag. Unfortunately I get exception : Caught: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.lang.Class any ideas how I can create such tag? import groovy.xml.StreamingMarkupBuilder import org.custommonkey.xmlunit.* import groovy.xml.XmlUtil def xml = new StreamingMarkupBuilder().bind{ 'use'(name:'Name', type:'type', year:2006) { desc('desc') } } println xml.toString() 回答1: You have to use the

How to write xml into a file using MarkupBuilder

杀马特。学长 韩版系。学妹 提交于 2019-12-11 00:45:07
问题 I created an xml using MarkupBuilder in groovy but how do i write it into a xml file in my project dir E:\tomcat 5.5\webapps\csm\include\xml def writer = new StringWriter() def xml = new MarkupBuilder(writer) String[] splitted xml.rows() { for(int i=0;i<lines.length-1;i++){ row() { for(int j=0;j<lines[i].length();j++) { splitted= lines[i].split(','); } name(splitted[0]) email(splitted[1]) } } } here println writer.toString() prints my whole xml content but i need it in a file in my tomcat

Omit empty attributes with groovy DOMBuilder

偶尔善良 提交于 2019-12-10 22:58:37
问题 Groovy's MarkupBuilder has an omitNullAttributes and an omitEmptyAttributes . But DOMBuilder doesn't. This is the code I have >>> def xml = DOMBuilder.newInstance() >>> def maybeEmpty = null >>> println xml.foo(bar: maybeEmpty) <foo bar=""/> I want bar to be omitted if empty. I found a workaround in an answer to Groovy AntBuilder, omit conditional attributes... to findAll empty attributes and remove them. Since I have a complex DOM to be generated, I'm looking for other options. 回答1: I

Groovy: copy XML elements from one doc to another

那年仲夏 提交于 2019-12-07 13:07:32
问题 I am new to Groovy and am stuck with a simple problem. All I wanna do is extract certain elements from one XML file and created a new file with it. Here's an example XML, let's use a Maven pom file: <project> <modelVersion>4.0.0</modelVersion> <groupId>com.group</groupId> <artifactId>artifact</artifactId> <version>1.4</version> <dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> <

Groovy: copy XML elements from one doc to another

折月煮酒 提交于 2019-12-05 20:50:43
I am new to Groovy and am stuck with a simple problem. All I wanna do is extract certain elements from one XML file and created a new file with it. Here's an example XML, let's use a Maven pom file: <project> <modelVersion>4.0.0</modelVersion> <groupId>com.group</groupId> <artifactId>artifact</artifactId> <version>1.4</version> <dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> I know how to parse XML in Groovy: def project = new XmlParser()

Use of Namespaces in Groovy MarkupBuilder

自作多情 提交于 2019-12-05 01:55:23
问题 I want have the following output: <?xml version="1.0" encoding="UTF-8"?> <structure:structuralDataRoot xmlns:register="http://www.test.ch/register/1" xmlns:structure="http://test.ch/structure/1" > <structure:tester>ZH</structure:tester> <structure:surveyYear>2001</structure:surveyYear> <structure:surfaceData> <structure:houseSurfaceData> <structure:creationDate>2001-01-01</structure:creationDate> <structure:localFarmId> <register:houseIdCategory>token</register:houseIdCategory> <register

Detecting first and last item inside a Groovy each{} closure

本小妞迷上赌 提交于 2019-11-28 23:56:02
问题 I am using Groovy's handy MarkupBuilder to build an HTML page from various source data. One thing I am struggling to do nicely is build an HTML table and apply different style classes to the first and last rows. This is probably best illustrated with an example... table() { thead() { tr(){ th('class':'l name', 'name') th('class':'type', 'type') th('description') } } tbody() { // Add a row to the table for each item in myList myList.each { tr('class' : '????????') { td('class':'l name', it