xmlslurper

How to apply predicate to GPath when I am using XMLSlurper

孤者浪人 提交于 2019-12-11 20:37:17
问题 lets say I have the following XML <InvoiceLines> <InvoiceLine> <InsertionDate>29.01.2015</InsertionDate> <Productnbr>0102</Productnbr> </InvoiceLine> <InvoiceLine> <InsertionDate>29.02.2015</InsertionDate> <Productnbr>0103</Productnbr> </InvoiceLine> </InvoiceLines> and I would like to get the insertion date of InvoiceLine that has Productnbr = 0103. If I would write xpath I would write somthing like: //InvoiceLine[./Productnbr='0103']/InsertionDate but I would like to use GPath since I am

XmlSlurpur The prefix “something” for element “something:element” is not bound

♀尐吖头ヾ 提交于 2019-12-11 10:49:10
问题 I am using XmlSlurper like so: def slurper = new XmlSlurper().parseText(xmlObj.lensData).declareNamespace(something:'something') when i slurp the following xml it give an error: <something:Data> <something:Requirements> <something:Type> <something:Value>T</something:Value> <something:Label>TYP</something:Label> </something:Type> </something:Requirements> </something:Data> the error i get is: The prefix "something" for element "something:Data" is not bound.. Stacktrace follows: Message: The

Groovy XMLSlurper - searching sepecific node

十年热恋 提交于 2019-12-11 08:44:30
问题 I need to find a specific node with Groovy's XMLSlurper. The condition should be that the text/value of the children nodes have to match. In the following example I want to search for a book node where the year is '2003' and the price is '39.95'. <bookstore name="Store A"> <employee> <id>546343</id> <name>Dustin Brown</name> </employee> <employee> <id>547547</id> <name>Lisa Danton</name> </employee> <book category="cooking"> <title lang="en">Everyday Italian</title> <author>Giada De

XmlSlurper Issue while Parsing

跟風遠走 提交于 2019-12-11 07:17:20
问题 I have XML as below, <div class="storeContainer"> <div class="storeCount">50</div> <div class="mapAddress" id="store50"> <h4 onclick="changeMap(50,38.872432,-78.530463);">Woodstock, VA</h4> <h5>Woodstock Square</h5>467 West Reservoir Road <br/>540-459-7505 <br/> <a href="https://maps.google.com/maps?saddr=geo&daddr=467+West+Reservoir+Road+Woodstock+VA+22664&sll=38.872432,-78.530463&sspn=0.011265,0.014098&z=12" class="getDirections">Get Directions</a> </div> </div> </div> I wanted to read

Groovy XMLSlurper issue

浪子不回头ぞ 提交于 2019-12-11 07:00:06
问题 I want to parse with XmlSlurper a HTML document which I read using HTTPBuilder. Initialy I tried to do it this way: def response = http.get(path: "index.php", contentType: TEXT) def slurper = new XmlSlurper() def xml = slurper.parse(response) But it produces an exception: java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd I found a workaround to provide cached DTD files. I found a simple implementation of class which

Groovy XmlSlurper get value of the node without children

倾然丶 夕夏残阳落幕 提交于 2019-12-11 01:38:22
问题 I'm parsing HTML and trying to value of a parent node itself, without values of the children nodes. HTML example: <html> <body> <div> <a href="http://intro.com">extra stuff</a> Text I would like to get. <a href="http://example.com">link to example</a> </div> </body> </html> Code: def tagsoupParser = new org.ccil.cowan.tagsoup.Parser() def slurper = new XmlSlurper(tagsoupParser) def htmlParsed = slurper.parseText(stringToParse) println htmlParsed.body.div[0] However above code returns: extra

Groovy XmlSlurper parse mixed text and nodes

橙三吉。 提交于 2019-12-11 00:42:14
问题 I'm currently trying to parse a node in groovy which contains mixed text and nodes with text and I need to get the text in the right order for example: <?xml version="1.0" encoding="UTF-8"?> <root> <p> The text has <strong>nodes</strong> which need to get parsed </p> </root> Now I want it to parse so I get the whole text but can still edit the node. In this example I want the result: The text has <b>nodes</b> which need to get parsed If I could just get a list of all elements under the p

XmlSlurper/NekoHTML document fragment parsing - No HTML or BODY tags wanted

廉价感情. 提交于 2019-12-10 12:19:34
问题 Dear All, I am trying to parse the following HTML fragment, and I would like to get the same fragment as output (without HTML and BODY tags). Is this possible? If so, how? Thank you Misha p.s. I am reading here: http://nekohtml.sourceforge.net/faq.html#fragments and I believe I have added the correct options below. However, the output is still incorrect :( Thank you Misha import groovy.xml.MarkupBuilder import groovy.xml.StreamingMarkupBuilder import groovy.util.XmlNodePrinter import groovy

groovy Print path and value of elements in xml

断了今生、忘了曾经 提交于 2019-12-10 10:53:29
问题 I have the following xml: <list> <cars> <model>2012</model> <make>GM</make> </cars> </list> I want to print these values as path:value as shown below. list/cars/model : 2012 list/cars/make : GM How can I achieve this? I tried the name() method but it only prints the name of child item. I want to print the whole path till the element. I can only use xmlSlurper parser to do this. Thanks. 回答1: import groovy.util.XmlSlurper import groovy.util.slurpersupport.NodeChild; def rootNode = new

XmlSlurper: How to change the text of a dynamic node

夙愿已清 提交于 2019-12-08 19:36:23
问题 <Messdaten> <EL_NR>NAYP99</EL_NR> <EL_NR_Original/> <Erfassungsdatum>2012-12-12 11:58:54.000</Erfassungsdatum> <Massnahme>Lot_Hold</Massnahme> <Anzahl_x0020_R>50</Anzahl_x0020_R> <FEHLER>OK</FEHLER> <SEQ>72</SEQ> </Messdaten> That is my XML and i want to change the value of node 'Anzahl_x0020_R'. The problem is, at runtime i don't know the exact name. I only know that the node to change will start with 'Anzahl'. So i did this: messdatenXML.childNodes().each { merkmal -> if (merkmal.name