Menu
  • HOME
  • TAGS

soapui how to get the list of nodes by using local-name in xpath expression?

Tag: xpath,soapui,xml-namespaces

I am using soapui for automation testing. I am trying to write a xpath expression to do the property transfer with following xml

<snapshots query="after=2014-04-16 12:30:00-0700" mask="op" xmlns="http://ws.example.com/roma/201907" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <AsOf>2014-04-16T19:20:44-07:00</AsOf>
    <offers>
        <offer entityId="6500588"/>
        <offer entityId="6500589"/>
        <offer entityId="6500590"/>
        <offer entityId="6557335">
            <rubber>KJM</rubber>
            <code>B44733</code>
            <offerCode>PA</offerCode>
            <status name="Completed">C</status>
            <startDate basis="GMT-4">2013-04-01</startDate>
            <endDate basis="GMT-4">2014-04-15</endDate>
            <template>
                <sourceKey-Ref entityId="36KTV" code="KPA513C36KTV" uri="/snapshot/sourcekey/36KTV"/>
                <pTemplateCode>PPAKXC</pTemplateCode>
                <panelCode>HPA5LTM</panelCode>
                <itemCode>PA1467</itemCode>
            </template>
            <venue code="28">
                <supervenue>5</supervenue>
            </venue>
            <currencyDetail currency="USD">
                <unitPrice>29.95</unitPrice>
                <numberPayments>1</numberPayments>
            </currencyDetail>
            <hData>
                <legacyScriptCode>300</legacyScriptCode>
                <hpKeycode>189161</hpKeycode>
                <hpProductNumber>014399</hpProductNumber>
                <hpMpgCode>300</hpMpgCode>
            </hData>
        </offer>
        <offer entityId="6557336">
            <rubber>KJM</rubber>
            <code>B44734</code>
            <offerCode>VY</offerCode>
            <status name="Completed">C</status>
            <startDate basis="GMT-4">2013-04-01</startDate>
            <endDate basis="GMT-4">2014-04-15</endDate>
            <template>
                <sourceKey-Ref entityId="36KTV" code="KPA513C36KTV" uri="/snapshot/sourcekey/36KTV"/>
                <pTemplateCode>PPAKXC</pTemplateCode>
                <panelCode>HPA5LTM</panelCode>
                <offerCode>OVYC8UM9</offerCode>
                <itemCode>VY4023</itemCode>
            </template>
            <venue code="28">
                <supervenue>5</supervenue>
            </venue>
            <currencyDetail currency="USD">
                <unitPrice>0.00</unitPrice>
                <numberPayments>1</numberPayments>
            </currencyDetail>
            <hData>
                <legacyScriptCode>947</legacyScriptCode>
                <hpKeycode>189162</hpKeycode>
                <hpProductNumber>602185</hpProductNumber>
                <hpMpgCode>947</hpMpgCode>
            </hData>
        </offer>
        <offer entityId="6557337">
            <rubber>KJM</rubber>
            <code>B44736</code>
            <offerCode>VY</offerCode>
            <status name="Completed">C</status>
            <startDate basis="GMT-4">2013-04-01</startDate>
            <endDate basis="GMT-4">2014-04-15</endDate>
            <template>
                <sourceKey-Ref entityId="36KTV" code="KPA513C36KTV" uri="/snapshot/sourcekey/36KTV"/>
                <pTemplateCode>PPAKXC</pTemplateCode>
                <panelCode>HPA5LTM</panelCode>
                <offerCode>OVYC8UMA</offerCode>
                <itemCode>VY4012</itemCode>
            </template>
            <venue code="28">
                <supervenue>5</supervenue>
            </venue>
            <currencyDetail currency="USD">
                <unitPrice>0.00</unitPrice>
                <numberPayments>1</numberPayments>
                <firstPaymentAmount>0.00</firstPaymentAmount>
                <firstShippingAmount>5.98</firstShippingAmount>
            </currencyDetail>
            <hData>
                <legacyScriptCode>947</legacyScriptCode>
                <hpKeycode>189163</hpKeycode>
                <hpProductNumber>602094</hpProductNumber>
                <hpMpgCode>947</hpMpgCode>
            </hData>
        </offer>
    </offers>
</snapshots>

I would like to have all hpKeycode using local-name() in the XPath expression. I tried

//*[local-name()='hpKeycode']

but this gives me only the first node which is 189161. This

/*[local-name()='hpKeycode'][2]

also does not work. Any help would be greatly appreciated.

Best How To :

You can try with XQuery. In the property transfer step select Use XQuery checkbox as you see in the image below. And use this code:

declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns1='http://ws.example.com/roma/201907';
<ns1:offer>
{
  for $id in //*[local-name()='hpKeycode'] return string($id)
}
</ns1:offer>

SOAPUI property transfer XQuery

EDIT:

If you want to avoid the use of XQuery, you can add three Transfers on your property transfer, on each one use:

First id (//*[local-name()='hpKeycode'])[1]

Second id (//*[local-name()='hpKeycode'])[2]

Third id (//*[local-name()='hpKeycode'])[3]

SOAPUI property transfer XPath

Hope this helps,

Java Selenium - Can't seem to select an element

java,selenium,xpath,hidden

Do you get any exceptions thrown? if the element is not visible then a NoSuchElementException will be thrown. Other then that, i would suggest making your xpath more readable, something like the following: String emailAddress = driver.findElement(By.xpath("//span[@class='email']")).getText(); ...

XPath query: parsing multiple paths using the same query (Cross Apply / .nodes() )

sql-server,xml,tsql,xpath

There is no way you can construct XQuery parameter dynamically as it is limited to literal string only. See what MSDN says about the parameter of nodes() XML method : XQuery Is a string literal, an XQuery expression. If the query expression constructs nodes, these constructed nodes are exposed in...

Combine multiple tags with lxml

python,html,xpath,lxml

I have managed to solve my own problem. for p in self.tree.xpath('//body/p'): if p.tail is None: # some conditions specifically for my doc children = p.getchildren() if len(children)>1: for child in children: #if other stuffs present, break if child.tag!='strong' or child.tail is not None: break else: # If not break,...

xpath query seem to be failing

xml,xpath

$str = '<root><Pages> <copyright>me inc. 2015,</copyright> <author>Me</author> <lastUpdate>2/1/1999</lastUpdate> <Home>--------------------</Home> <About>--------------------</About> <Contact>------------------</Contact> </Pages></root>'; $xml = simplexml_load_string($str); $result = $xml->xpath('//Pages/*[(name() = "Home") or following-sibling::Home]'); if ($result === false) { $this->parseError(); //To return xml Error code...

selenium webdriver - xpath locator not working if element's text contains Unicode Characters

selenium,xpath,unicode,selenium-webdriver,webdriver

Am I missing something here? Yes, I think so: <div class="menuitem-content">Français</div> the "a" is missing driver.findelement(By.XPath("//div[text()='Françis']")); EDIT: At least in a Java environment Webdriver can handle Unicode. this works for me (driver in this case being an instance of FirefoxDriver): driver.get("https://fr.wikipedia.org/wiki/Mot%C3%B6rhead"); WebElement we = driver.findElement(By.xpath("//h1[contains(., Motörhead)]")); System.out.println(driver.getTitle() + "...

Can't get value from xpath python

python,html,xpath,web-scraping,html-parsing

The values in the table are generated with the help of javascript being executed in the browser. One option to approach it is to automate a browser via selenium, e.g. a headless PhantomJS: >>> from selenium import webdriver >>> >>> driver = webdriver.PhantomJS() >>> driver.get("http://www.tabele-kalorii.pl/kalorie,Actimel-cytryna-miod-Danone.html") >>> >>> table = driver.find_element_by_xpath(u"//table[tbody/tr/td/h3...

Update Text Field While Automating iPhone App

iphone,xpath,textbox

Call this method before passing the value to the Locator. method_name(){ Actions actionObj = new Actions(driver); actionObj.keyDown(Keys.CONTROL) .sendKeys(Keys.chord("A")) .keyUp(Keys.CONTROL).keyUp(keys.DELETE) .perform(); } findElement By xpath add a condition like getText()!="" and then It will be done. Is it working??...

Python XPath include missing elements

python,xml,xpath,xml-parsing

I would use findtext() and specify the default: [item.findtext("optional_element", default="") for item in tree.findall("item")] Demo (using lxml): >>> from lxml import etree >>> >>> data = """<?xml version="1.0" encoding="utf-8"?> ... <tree> ... <item> ... <element1>somedata</element1> ... <element2>moredata</element2> ... <element3>data?</element3> ... <optional_element>data!</optional_element> ... </item> ... <item> ......

Adding a child attribute to the parent element in xslt 1.0

xml,xslt,xpath,xslt-1.0

It's difficult to provide an answer without seeing the input. I believe you need to do something like the following: XSLT 1.0 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="visualChildren"> <xsl:variable name="bundles"> <xsl:call-template name="create-bundles"> <xsl:with-param name="n" select="4" />...

how to make xml values comma seperated using XPath, XQuery in Sql Server

sql-server,xml,xpath,xquery

SQL Server does not implement the xPath function string-join, so you would need to adopt a two step process, the first would be to extract all the terms to rows using nodes(); SELECT n.value('.', 'VARCHAR(100)') AS parsedString FROM #temp AS t CROSS APPLY t.Response.nodes('/error/description2') r (n); Which gives you your...

Remove Duplicate XML Records

c#,linq,xpath

I have been able to come up with a solution for you by writing this code: string file = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "xml.txt"); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(file); var el = xmlDoc.SelectSingleNode("/Fare_1"); var c = el.ChildNodes; List<string> rateClassValues = new List<string>(); foreach (XmlNode x in c) { foreach(XmlNode ch in...

How to retrieve ATTRIBUTE VALUE from specific ELEMENT VALUE in C#

c#,xml,xpath

How about this: //Time[text() = '...']/@hours ...

XPath query to select ONLY unique nodes

c#,xml,xpath,selectnodes

All Person tags that has not Person tag with the same PersonID before //Person[not(PersonID = preceding::Person/PersonID)] it gives you nodes Person with children. In this case 4 elements: Element='<Person> <PersonID>6352</PersonID> <Forename>Tristan</Forename> </Person>' Element='<Person> <PersonID>6353</PersonID> <Forename>Ruth</Forename> </Person>' Element='<Person> <PersonID>6913</PersonID> <Forename>Mina</Forename>...

How to set up XPath query for HTML parsing?

python,xml,parsing,xpath,lxml

It is important to inspect the string returned by page.text and not just rely on the page source as returned by your Chrome browser. Web sites can return different content depending on the User-Agent, and moreover, GUI browsers such as your Chrome browser may change the content by executing JavaScript...

XPath does not work with XMLReader and SimpleXML? [duplicate]

php,xml,xpath,simplexml,xmlreader

Your while, seems, not executed even once. Code should read, until needed condition will occur while($reader->read()) { if (reader->nodeType == XMLREADER::ELEMENT && $reader->name == 'XMLSOCCER.COM') ) { $xml = simplexml_import_dom($dom->importNode($reader->expand(),true)); $pathXML = $xml->xpath('//Odds[contains(Bookmaker,"Interwetten")]'); /*if($this->getExpression()){ $xml->xpath($this->getExpression()); }*/ break; } } ...

group siblings by identifying the first node of a certain type in sequence

xml,xslt,xpath

Try it this way: <xsl:key name="kFirstText" match="*[not(self::type1[not(preceding-sibling::*[1][self::type1])])]" use="generate-id(preceding-sibling::type1[not(preceding-sibling::*[1][self::type1])][1])"/> This excludes the "leader" nodes from the group retrieved by the key....

Java XPath returns single result instead of NodeSet

java,xml,dom,xpath

My guess is that you make a mistake while processing the result NodeList. Try the following approach: NodeList results = (NodeList) xpath.evaluate(..); for (int i = 0; i < nodelist.getLength(); i++) { Node node = (Node) nodelist.item(i); ... } ...

How to get testStep responseAsXml in groovyScript

groovy,soapui

If you want to get the response from com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep, a possible way is first get the testStep from this class using getTestStep() method. This method returns a object of class com.eviware.soapui.model.testsuite.TestStep, from this object you can get the testSteps properties like request, response, endpoint... using getPropertyValue(java.lang.string) method. So in your...

Xpath text() wrong output

python,xpath,web-scraping,scrapy

Wow, I feel stupid. The answer just came to me. I forgot to call .extract() on the temp variable in the parse function of my spider class.

Error when building an XDocument

c#,xml,linq,xpath,linq-to-xml

You can ignore pretty much all your code, the issue is just this: XDocument people = new XDocument("Persons"); You can't create an XDocument containing a string, you need to add an element: XDocument people = new XDocument( new XElement("Persons", original.XPathSelectElements(xpathFilterDups))); ...

What version of XPath does XmlDocument.SelectSingleNode use?

c#,.net,xml,xpath

Microsoft never implemented XPath 2.0 or Xslt 2.0... See for example this uservoice (aptly named Native support for XPath 2.0 or XSLT 2.0 in .NET) of 2013... Last comment of March 2015 by one user: i guess we will never see this as the world doesn't like XML anymore, it's...

Convert contents of an XmlNodeList to a new XmlDocument without looping

c#,xml,xpath,xmldocument,xmlnodelist

If you're happy to convert it into LINQ to XML, it's really simple: XDocument original = ...; // However you load the original document // Separated out for clarity - could be inlined, of course string xpath = "//Person[not(PersonID = following::Person/PersonID)]" XDocument people = new XDocument( new XElement("Persons", original.XPathSelectElements(xpath) )...

Transform XML structure using XSLT

xml,xslt,xpath

If you want to use conditions on nodes then I would suggest to put them into match patterns: <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="detaileddescription/para[bold][following-sibling::*[1][self::para[.//para]]]"> <List> <Title>...

What is the xpath for retrieving all attribute nodes (whatever be the attributes name) with a specified value?

java,xml,xpath

Well //@* gives you all attribute nodes, add a predicate //@*[. = 'zzz'] and you have all attribute nodes with the value zzz.

Linq in C++ CLI

xml,linq,visual-c++,xpath,c++-cli

I was able to rewrite your code in such a way: using namespace System; using namespace System::Collections::Generic; using namespace System::Xml::Linq; using namespace System::Xml::XPath; ref class cROI { public: property int iX ; property int iY ; property int iWidth ; property int iHeight; cROI (int piX, int piY,int piWidth,int piHeight...

Selection skipping node on missing childnode

xpath,vbscript,xml-parsing

The code you posted can't possibly work with the XML you posted. There is no method SelectSingleNodes. It's either SelectNodes or SelectSingleNode. The <uv> nodes are immediate children of the <point_forecast> nodes. An XPath expression */uv would match grandchildren (like with */point_forecast). The attribute index is not the text (content)...

I want to find the xpath for day separated by

java,html,xpath,selenium-webdriver

This is sunday //span[contains(.,'Consis')]/parent::td/following-sibling::td/span[contains(.,'Sun')]/text()[1] respectively, [2] is monday Below part, containing sunday //span[contains(.,'Consis')]/parent::td/following-sibling::td/span/text()[contains(.,'Sun')] ...

Test XML content without using mock mvc

xml,spring,unit-testing,xpath,spring-test

No, it's not possible to reuse XpathResultMatchers without MockMvc and related classes. However... the code in question (in your pseudo-code example), delegates internally to Spring's XpathExpectationsHelper. So you can invoke -- for example -- the exists() method directly on an instance of XpathExpectationsHelper if you so desire. As an alternative,...

xslt condition output one by one

xml,function,xslt,if-statement,xpath

Try: <xsl:template match="blabla"> <all> <xsl:for-each select="a"> <a n="{@n}"> <xsl:copy-of select="../b[@n >= current()/@n]"/> </a> </xsl:for-each> </all> </xsl:template> ...

How to remove the line breaks in front of a tag in Xpath

python,xpath

On the Python side, you could use str.strip() to remove whitespace from both sides of the string: In [290]: data = ['\n\t\t\tCC=O'] In [291]: data[0].strip() Out[291]: 'CC=O' or, on the XPath side, you could use normalize-space: In [299]: tree.xpath('normalize-space(//*[text()="Smiles"]/..//br[1]/preceding-sibling::text())') Out[299]: 'CC=O' Note that in addition to removing both leading and...

XSL transformation outputting multiple times and other confusion

xml,xslt,xpath

1) Your template is applied to 3 elements, and for each of them, loops over all the parents li elements (yes, for each of them, ask all the li elements, children of the grand-father of the current content, which are all the 3 li elements, each time). 2) Because that's...

Difference between ancestor and ancestor-or-self

xslt,selenium,xpath,selenium-webdriver

Ancestor and Ancestor-or-self are the XPath Axes. An axis is a node-set relative to the current node. The ancestor axis selects all the ancestors, i.e. parent, grandparent, etc of the current node whereas the ancestor-or-self selects all the ancestors, i.e. parent, grandparent, etc. of the current node and the current...

How to get xml Nodes which are in lower case using XSLT 1.0

xml,xslt,xpath,xslt-1.0

All you need is the identity template to copy existing nodes... <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> Then another template to ignore nodes that aren't lower-case. In XSLT 1.0 this can be done by using the translate statement, to translate uppercase letters to lowercase, and checking if the result...

Seach by class in Nokogiri nodeset

ruby,xpath,nokogiri

Assuming that the class name is stored into class_name, I think that doc.xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' #{class_name} ')]") is what you're looking for. This will match all the elements that contain class_name into their classes, ie if class_name is 'box', then it will match both elements like div...

XSL getting out of context using dynamic XPATH

xslt,xpath

Dynamic evaluation (treating a string in a variable as an XPath expression and evaluating it) is available as a vendor extension in a number of XSLT processors, and it becomes part of the standard with the introduction of xsl:evaluate in XSLT 3.0. If your XSLT processor doesn't have such an...

Is there a bug in xpathSApply if you produce your own XML object?

xml,r,xpath

This is definitely a bug. Note that , this works fine: xpathSApply(top,'//A/b') ## without attribute As a workaround, you can get the attribute using xmlGetAttr: xpathSApply(top,"//A/b",xmlGetAttr,"x") ...

XPath query to select nodes

c#,xml,xpath,xmlnodelist

You can use the following XPath : //Person[not(Surname)] ...

XML-XSLT-XPATH : How to convert multiple XML elements to a string, separated by semicolon

xml,xslt,xpath,xslt-2.0

you could use something like: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>UserNames: &quot;</xsl:text> <xsl:value-of select="/Users/user/username" separator=";"/> <xsl:text>&quot;&#xA;</xsl:text> <xsl:text>Names: &quot;</xsl:text> <xsl:value-of select="/Users/user/name" separator=";"/>...

How to reject specify HTML tags by using css or xpath selector

javascript,css,ruby,xpath,nokogiri

Simpler is just: doc.search('style,script').remove ...

How to remove nodes above and below somewhere in the document

c#,html,xpath,html-agility-pack

According to your HTML sample (and commonly it is), <table> is child of <body>, they are not at the same level. Assuming that table is a variable of type HtmlNode pointing to the <table> element, you can do this way : var nodes = table.SelectNodes("following-sibling::*[1] | preceding-sibling::*[1]"); foreach (HtmlNode node...

Count unique values in comma separated value in xslt 1.0

xpath,xslt-1.0

It's possible without nodesets. It's not optimal, of course (hello, Shlemiel The Painter), but it's pretty easy - increment counter only if there is no given string ahead or behind. Template <xsl:template name="calcUnique"> <xsl:param name="str"/> <xsl:param name="back"/> <xsl:param name="count"/> <xsl:if test="$str"> <xsl:choose> <xsl:when test="contains($str, ',')"> <xsl:variable name="part" select="substring-before($str, ',')"/> <xsl:call-template...

Adding a public class to click using xpath with Java Selenium

java,selenium,xpath

You are passing a String: ClickByXpath(driver, "/html/body/div/div[3]/form/div[2]/div[2]/div[1]/div[1]/div[3]/div/div[3]/div/input[1]"); But you method signature says that you should pass a String Array: public static void ClickByXpath(WebDriver [] driverUsed , String[] XPath_to_click) Same problem with your driver! If you change the signature and remove the Arrays, you should be good: public static void ClickByXpath(WebDriver...

Unable to construct Document object from xml string

java,xml,xpath,xml-parsing

As Arthur Elrich pointed out in the comments, you should make the factory namespace aware and provide a namespace context to the XPath instance. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse( new InputSource(new StringReader(...))); XPath xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(new MyNamespaceContext()); String s = xpath.evaluate("//location:address/text()",...

Load just XPath search to XMLReader memory?

php,xpath,simplexml,xmlreader

You are still searching the entire OddsList. Try using the XMLReader something like this: $reader = new XMLReader(); $reader->open($url); $dom = new DomDocument(); // Find first occurrence of Odds while ($reader->read() && $reader->name !== 'Odds'); // Iterate Odds while ($reader->name === 'Odds'){ $odds = simplexml_import_dom($dom->importNode($reader->expand(), true)); // Process those having...

Unable to select text boxes in selenium webdriver through XPath?

selenium,xpath

Change expression so //input[@type='text' and not(@disabled ='disabled')] ...

XPath for child element

selenium,xpath

//div[contains(concat(' ',@class,' '), ' A ')]//div[contains(concat(' ',@class,' '), ' B ')][1] ...

Save SOAP UI mock requests to a file

web-services,soap,request,soapui

If you want to save in a file all request that your Mock service recieve, simply do the follow. In your mock service open the onRequest script tab as in the follow image (this script executes each time that your service receives a request): And add the follow groovy script...

XSLT insert sibling if it doesn't exist - Not being rerunnable for some reason

xml,xslt,xpath

Your template matches a sec:authentication-provider element: match="bi:realm/sec:authentication-provider[...]" So, within the template, the context node is the matched sec:authentication-provider element. Therefore, when you perform your test, you need to proceed from that context. Your current test test="not(bi:realm/sec:authentication-provider[@xsi:type='ext:session-authenticatorType'])" would only work if the context node were the parent of bi:realm, namely bi:security-configuration....

webdriver C# - click this element with XPath position?

c#,selenium,xpath,webdriver

Shouldn't you be using: river.FindElement(By.XPath("//td[4]/a")).Click(); ? And if you have similiar Problems. You can use the Console in the developer tools of Chrome and write like this: $x("YOUR XPATH HERE") This will result in your element. If that's not the case, then your Xpath is wrong. Edit: If you want...

Can I create a macro or shortuct for a step of XPath in XQuery?

xml,xpath,macros,xquery

XQuery does not know such macros, you could of course use any preprocessor to do such things. But I'd rather define a function for this: declare function local:outward($context as item()) { $context/ancestor-or-self::* }; Functions can also be applied in axis steps (remember to pass the current context .): let $xml...