xmlslurper

How Can I Use Config Entries with Dots When Parsing with XmlSlurper

与世无争的帅哥 提交于 2019-12-24 13:14:57
问题 I'm trying to use a groovy Config entry to parse an xml file with XmlSlurper. Here's the Config file: sample { xml { frompath = "Email.From" } } Here's the XML <xml> <Email> <From> <Address>foo@bar.com</Address> <Alias>Foo Bar</Alias> </From> <Email> </xml> This is what I tried initially: XmlSlurper slurper = new XmlSlurper() def record = slurper.parseText((new File("myfile.xml")).text) def emailFrom = record?."${grailsApplication.config.sample.xml.frompath}".Address.text() This doesn't work

XML Parsing with same element tags but unique data

最后都变了- 提交于 2019-12-24 07:29:37
问题 I am parsing xml that has many of the same tag. Inside the tag there is a name of a value and then the value. My issue is is that I need to separate those values. This is an example of the xml I have to parse <Event> <ipaddress> 10.0.0.0. </ip> <sourcesystem> somwhere </sourcesystem> <username> fred91 </username> <user> <username> fred91 </username> <account> fredsaccount </account> <id> f2234232 </id> </user> ////BELOW IS THE PORTION OF THE XML THAT I AM HAVING ISSUES WITH NOTICE MULTPLE OF

Parsing (very) large XML files with XmlSlurper

风流意气都作罢 提交于 2019-12-23 10:53:12
问题 I am kind of new to Groovy and I am trying to read a (quite) large XML file (more than 1Gb) using XmlSlurper, which is supposed to work wonders with large files due to the fact that it doesn't build the whole DOM in memory. Nevertheless I keep getting "OutOfMemoryError : Java heap space" which makes me think that there obviously is something that I'm doing wrong. I tried increasing the Xmx setting but I would rather solve the problem since I may have to deal with even bigger files afterwards.

Is it possible to parse sub-trees with Groovy XMLSlurper

南笙酒味 提交于 2019-12-22 09:50:09
问题 Does anyone know whether it is possible to utilise XMLSlurper in a fashion that means individual sub-trees can be pulled from a very large XML document and processed individually? Imagine you've got a huge XML feed containing a root element that has thousands of direct child elements that you can process individually. Obviously, reading the whole document into memory is a no-no but, as each child of the root is itself modestly sized, it would be nice to stream through the document but apply

How to I use a variable reference within XMLSlurper statement

寵の児 提交于 2019-12-20 05:43:39
问题 I am using a groovy with XMLSlurper to validate my web service responses in soap ui pro. I have the following code which works (expectedResponse is var that stores expected errorcode e.g. E0023) ... if(expectedResponse2 in slurper.Body.createShipmentResponse.integrationFooter.errors.error.errorCode.collect{it.text()}) { result = "pass" } But I would like to replace the 'integrationFooter.errors.error.errorCode' with a reference to a variable that I could supply from a SoapUI Pro datasource,

Namespace handling in Groovys XmlSlurper

被刻印的时光 ゝ 提交于 2019-12-18 13:19:40
问题 The situation: def str = """ <foo xmlns:weird="http://localhost/"> <bar>sudo </bar> <weird:bar>make me a sandwich!</weird:bar> </foo> """ def xml = new XmlSlurper().parseText(str) println xml.bar The output of this snippet is # sudo make me a sandwich! It seems like the parser merges the contents of <bar> and <weird:bar> . Is this behavior desired and if yes, how can I avoid this and select only <bar> or <weird:bar> ? 回答1: By default XMLSlurper is not namespace aware. This can be turned on by

How to remove an element in Groovy using XmlSlurper?

倾然丶 夕夏残阳落幕 提交于 2019-12-18 06:51:11
问题 For example, how can I remove all tags with name one in rootNode programmatically? def rootNode = new XmlSlurper().parseText( '<root><one a1="uno!"/><two>Some text!</two></root>' ) I tried rootNode.children().removeAll{ it.name() == 'one' } but it reported: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.NodeChildren.removeAll() is applicable for argument types: (DUMMY$_closure1_closure2) values: [DUMMY$_closure1_closure2@6c5f92d3] 回答1: Try rootNode.one

Properly iterating through XML with namespaces in Groovy

江枫思渺然 提交于 2019-12-13 00:06:11
问题 I have the following xml code: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <cms:RelatedConfigurationItemList xmlns:cms="some namespace"> <ConfigurationItem> <name>data</name> <id>data</id> <type>data</type> <relationship>IS CHILD OF</relationship> <ConfigurationItemList> <ConfigurationItem> <name>data</name> <id>data</id> <type>data</type> <relationship>IS CHILD OF</relationship> <ConfigurationItemList/> </ConfigurationItem> <ConfigurationItem>

Groovy XmlSlurper replace node with given child node value

早过忘川 提交于 2019-12-12 05:22:48
问题 I'd be grateful for help with the following problem. (I am new to Groovy, and I can't find any specific examples addressing my issue). Using XmlSlurper I am trying to replace an XML node which has a child with a certain value. For example, I want to transform: <assets> <!--zero to many asset nodes beforehand--> <asset> <name>MyPackageName</name> <data> <stringValue>my string value</stringValue> </data> </asset> <!--zero to many asset nodes afterwards--> </assets> into: <assets> <!--zero to

Using a variable to extract value of property of an element in groovy using xmlSlurper

眉间皱痕 提交于 2019-12-12 04:55:20
问题 I am using SoapUI to test webservices. The following string (in xml format) is my request: <Request> <AC> <AssetID>1</AssetID> <Asset_Name>ABC</Asset_Name> <Asset_Number>1</Asset_Number> </AC> <AC> <AssetID>2</AssetID> <Asset_Name>XYZ</Asset_Name> <Asset_Number>2</Asset_Number> </Ac> </Request> I am using the following code in a groovy script to extract value of Asset_Number for each AC (The above xml string is stored in variable strRequest): def x = new XmlSlurper().parseText("$strRequest")