I'm new to Xpath and I'm trying to figure out how to extract the attribute of the extension with the value of D000001602 as shown below.
<ClinDoc>
<ComponentOf>
<encompassingEncounter>
<id root="2.16.840.1.113883.3.52.3" extension="D000001602"/>
<effectiveTime>
<low value="20140620135800"/>
<high value="20140701140756"/>
</effectiveTime>
</encompassingEncounter>
</componentOf>
</ClinDoc>
I am using an online extractor with the following code but I can't seem to get it to work:
/clindoc/componentof/encompassingEncounter/id[#root=2.16.840.1.113883.3.529.3]/#extension
//id[#root=2.16.840.1.113883.3.529.3]/#extension
Thanks much!
You're trying to match root with the string value 2.16.840.1.113883.3.52.3, which means you need to represent it as a string literal in the XPath.
Also, node names are case sensitive:
/ClinDoc/Componentof/encompassingEncounter/id[#root="2.16.840.1.113883.3.529.3"]/#extension
Related
I have a website I need to isolate XPATH identifiers on - they have an XPath ID like this //*[#id="panel-detail-6163748c7952a-partnerCode"]
The issue is that the website changes the value 6163748c7952a on every page load.
Is there any such XPath expression which can match on the first/last part of that string? So of a wildcard like //*[#id="panel-detail-*-partnerCode"]
This XPath 2.0 expression,
//*[matches(#id, "^panel-detail-.*-partnerCode$")]
or this XPath 1.0 expression,
//*[starts-with(#id, 'panel-detail-') and
substring(#id, string-length(#id) - string-length('-partnerCode') + 1)
= '-partnerCode']
will match all elements whose id attribute value starts and ends with the noted substrings.
See also
XPath testing that string ends with substring?
There are few methods in xpath such as starts-with or ends-with. Many time folks replaces them with contains which should be discourage.
Please note that ends-with is available with xpath v2.0 .
xpath v1.0 :
//*[starts-with(#id,'panel-detail-') and contains(#id, '-partnerCode')]
xpath v2.0 :
//*[starts-with(#id,'panel-detail-') and ends-with(#id, '-partnerCode')]
I am new to XSLT, currently I have a json string and I need to derive particular field from the json string . I am currently using fn:parse-json with map:get but the resultant seems to be empty .
Below is the sample snippet:
<xsl:variable name="json-temp" select="fn:parse-json($json-str)" />
<xsl:variable name="result" select="map:get($json-temp,2)" />
When I try to print result (Or) json-temp both seems to be empty - Can someone please help here. and let me know if I am missing anything.
json-str variable has the following value:
{
"testName":"pppp",
"testID":"1234p",
"testDept":"Dept"
}
You should be able to use map:get($json-temp, 'testID') (in XPath 3) or $json-temp?testID in XPath 3.1. I am not sure which value you want to extract with map:get($json-temp,2) as the map has no key of the value 2, that call would only make sense for e.g. map { 2: 'foo' } to extract e.g. foo.
The best way to use JSON in DataPower is by using GatewayScript instead of XSLT. If you really need to stick to XSLT, you can try using:
<xsl:variable name="jsonx" select="dp:stringToJSONx($json-str)"/>
From there, you can extract the field you want by using XPath on the resulting JSONx document.
I am trying to scrape some specific content that sits within the <script> section of a page (at the bottom of the page before the end of the tag. It is my understanding that this can't be done with regular XPath, so I will be using PhantomJs cloud via SEOTools for Excel plugin.
Please see code below:
<script> window.__INITIAL_STATE__ = {"questions":{"list":{},"status":{}},"sites":{"list":{"SEOTest":{"joined":"2016-04-17T22:00:31.000Z","threshold":[],"abn":"8724483318952",
I want to be able to scrape the text after "ABN" field, so the xpath would return "8724483318952". Does anybody know how this can be done with xpath?
To retrieve the desired target string value of "8724483318952" you can use the following XPath-1.0 expression:
substring-before(substring-after(script,'abn":'),',')
It gets the desired string from the <script> tag and its output is
"8724483318952"
The signature of XPathUrl is, according to this link:
=XPathOnUrl(
string url,
string xpath,
string attribute,
string xmlHttpSettings,
string mode
) : vector
So the whole expression could look like this:
=XPathOnUrl(A2,"substring-before(substring-after(//ul[#class='headshot']/script,'abn":'),',')")
I'm not sure that this expression really does work, but it should give you a pretty precise idea of how to handle XPath expression generally.
I have a question about extracting a value with xpath
Some part of the xml:
<mark:info>
<mark:Information name="Adress" answer="SomeStreet"/>
<mark:Information name="PhoneNumber" answer="123456789"/>
</mark:info>
I want to receive the text "SomeStreet" with extractValue function in mysql
I was trying to create an xpath expression like
//mark:info/mark:Information[#name='Adress']
but I'm receiving the whole node. I need just the text "SomeStreet" but I'm not sure how to do it.
The xpath //mark:Information[#name="Adress"]/#answer should give SomeStreet
BTW shouldn't your xml have a xmlns specifying what is mark like :
<mark:info xmlns:mark="http://example.com"> ?
With Selenium IDE, how can I test if an element's inner text contains a specific string? For example:
<p id="fred">abcde</p>
'id=fred' contains "bcd" = true)
The Selenium-IDE documentation is helpful in this situation.
The command you are looking for is assertText, the locator would be id=fred and the text for example *bcd*.
It can be done with a simple wildcard:
verifyText
id="fred"
*bcd*
See selenium IDE Doc
You can also use:
assertElementPresent
css=p#fred:contains('bcd')
A solution with XPath:
Command: verify element present
Target: xpath=//div[#id='fred' and contains(.,'bcd')]
Are you able to use jQuery if so try something like
$("p#fred:contains('bcd')").css("text-decoration", "underline");
It seems regular expressions might work:
"The simplest character set is a character. The regular expression "the" contains three
character sets: "t," "h" and "e". It will match any line with the string "the" inside it.
This would also match the word "other". "
(From site: http://www.grymoire.com/Unix/Regular.html)
If you are using visual studio there is functionality for evaluating strings with regular expressions of ALL kinds (not just contains):
using System.Text.RegularExpressions;
Regex.IsMatch("YourInnerText", #"^[a-zA-Z]+$");
The expression I posted will check if the string contains ONLY letters.
Your regular expression would then according to my link be "bcd" or some string you construct at runtime. Or:
Regex.IsMatch("YourInnerText", #"bcd");
(Something like that anyway)
Hope it helped.
You can use the command assertTextPresent or verifyText