How can I get the texts by calling the attribute? - xpath

I have a code such as
<out:Names>
<out:Name Type="First" TypeCode="Best">JAE</out:Name>
<out:Name Type="Last" TypeCode="Best">ADAMS</out:Name>
</out:Names>
<out:Address>
<out:AddressLine Order="1" TypeCode="Best">33877 810TH AVE</out:AddressLine>
<out:City>GADSDEN</out:City>
</out:Address>
<out:Names>
<out:Name Type="First" TypeCode="Best">KATHY</out:Name>
<out:Name Type="Last" TypeCode="Best">GREEN</out:Name>
</out:Names>
<out:Address>
<out:AddressLine Order="1" TypeCode="Best">5th GARRISON AVE</out:AddressLine>
<out:City>Jersey City</out:City>
</out:Address>
How can I give the XPath expression in SOAPUI PRO so that I can get the result of all the first names/last names?

Related

Is possible to extract the text of an element compared with the end of the value of an attribute of current node?

I have an XML like this
<Values>
<Value ID="Contents01" Name="Contents 01" QualifierID="en-US">
<Text>It is a test [{placeHolder01}]</Text>
</Value>
<Value ID="VarPlaceHolderValue01" Name="Var Place Holder 01" QualifierID="en-US">[{placeHolder01}]</Value>
<Value ID="Contents02" Name="Contents 02" QualifierID="en-US">
<Text>Some extra text.</Text></Value>
<Value ID="PlaceHolder01" Name="PlaceHolder 01" QualifierID="en-US">
<Text>For StackOverflow</Text>
</Value>
</Values>
Would be possible to get with an expression the QualifierID of the PlaceHolderValue01, having the currently selected node the PlaceHolder01.
So the idea would be something like this from an already selected node.
//Values/Value[starts-with(#ID,'Var') and substring(./#ID, string-length(./#ID) - 2) = substring(#ID, string-length(#ID) - 2)]/text()
However I am getting syntax error with the xpath checkers, how it should work correctly?
Is it possible to do this with only xpath? The idea is to extract the text of the element VarPlaceHolderValue01, knowing that starts with Var and ends with the same number value of the current selected node?
Trying it out in iPython:
First, to select the node:
In [11]: root.xpath('//Value[starts-with(#ID, "PlaceHolder")]')
Out[11]: [<Element Value at 0x1094a1a00>]
Next, to isolate the string to be matched:
In [13]: root.xpath('substring-after(//Value[starts-with(#ID, "PlaceHolder")]/#ID, "PlaceHolder")')
Out[13]: '01'
Next, to match the "Var"-starting element and extract its text.
In [18]: root.xpath('string(//Value[starts-with(#ID, "Var") and contains(#ID, substring-after(//Value[starts-with(#ID, "PlaceHolder")]/#ID, "PlaceHolder"))])')
Out[18]: '[{placeHolder01}]'

SLD Filter function if_then_else argument #2 - expected type Object

I'm facing a problem with the GeoServer SLD XML.
My XML code is as follows:
<Fill>
<CssParameter name="fill">
<ogc:Function name="if_then_else">
<ogc:Function name="isNull">
<ogc:PropertyName>LTE_RSRP</ogc:PropertyName>
</ogc:Function>
<ogc:Literal>#FF0000</ogc:Literal>
<ogc:Function name="Interpolate">
<ogc:PropertyName>LTE_RSRP</ogc:PropertyName>
<ogc:Literal>-80</ogc:Literal>
<ogc:Literal>#ff0000</ogc:Literal>
<ogc:Literal>-70</ogc:Literal>
<ogc:Literal>#00ff00</ogc:Literal>
<ogc:Literal>-60</ogc:Literal>
<ogc:Literal>#0000ff</ogc:Literal>
<ogc:Literal>color</ogc:Literal>
</ogc:Function>
</ogc:Function>
</CssParameter>
<CssParameter name="fill-opacity">0.3</CssParameter>
</Fill>
My intention is as follows:
If LTE_RSRP is null, fill with #FF0000.
Else, interpolate the color.
But when the above XML is applied, the following error occurs.
ERROR [geotools.rendering] - Filter Function problem for function if_then_else argument #2 - expected type Object
Here, argument #2 is the function Interpolate. (argument counting starts from 0, according to the geotools source code.) It seems that the return value of the function Interpolate is not an object.
Is this intentional? Or am I doing something wrong?
This is intentional - how could a function that interpolates a colour map return an object? What you want to do can be done using Rules and Filters so something (untested) like this should work:
<Rule>
<ogc:Filter>
<ogc:PropertyIsNull>
<ogc:PropertyName>LTE_RSRP</ogc:PropertyName>
</ogc:PropertyIsNull>
</ogc:Filter>
<ogc:PolygonSymbolizer>
....
<Fill>
....
</Rule>
<Rule>
<ElseFilter/>
<PolygonSymbolizer>
....
<Fill>
<ogc:Function name="Interpolate">
<ogc:PropertyName>LTE_RSRP</ogc:PropertyName>
<ogc:Literal>-80</ogc:Literal>
<ogc:Literal>#ff0000</ogc:Literal>
<ogc:Literal>-70</ogc:Literal>
<ogc:Literal>#00ff00</ogc:Literal>
<ogc:Literal>-60</ogc:Literal>
<ogc:Literal>#0000ff</ogc:Literal>
<ogc:Literal>color</ogc:Literal>
</ogc:Function>
....

trying to parse specific data using xpath

I have a small xml file that I'm trying to grab the away_team first and then the home_team second.
/game/team/statistics/#goals gives me the data I want but I need to reverse the order. So I'm trying to understand how to get the away_team goals first, followed by the home_team.
Below is the file
<game id="f24275a9-4f30-4a81-abdf-d16a9aeda087" status="closed" coverage="full" home_team="4416d559-0f24-11e2-8525-18a905767e44" away_team="44167db4-0f24-11e2-8525-18a905767e44" scheduled="2013-10-10T23:00:00+00:00" attendance="18210" start_time="2013-10-10T23:08:00+00:00" end_time="2013-10-11T01:32:00+00:00" clock="00:00" period="3" xmlns="http://feed.elasticstats.com/schema/hockey/game-v2.0.xsd">
<venue id="bd7b42fa-19bb-4b91-8615-214ccc3ff987" name="First Niagara Center" capacity="18690" address="One Seymour H. Knox III Plaza" city="Buffalo" state="NY" zip="14203" country="USA"/>
<team name="Sabres" market="Buffalo" id="4416d559-0f24-11e2-8525-18a905767e44" points="1">
<scoring>
<period number="1" sequence="1" points="1"/>
<period number="2" sequence="2" points="0"/>
<period number="3" sequence="3" points="0"/>
</scoring>
<statistics goals="1" assists="2" penalties="7" penalty_minutes="23" team_penalties="0" team_penalty_minutes="0" shots="27" blocked_att="14" missed_shots="8" hits="25" giveaways="5" takeaways="10" blocked_shots="7" faceoffs_won="22" faceoffs_lost="28" powerplays="1" faceoffs="50" faceoff_win_pct="44.0" shooting_pct="3.7" points="3">
<powerplay faceoffs_won="2" faceoffs_lost="0" shots="0" goals="0" missed_shots="1" assists="0" faceoff_win_pct="100.0" faceoffs="2"/>
<shorthanded faceoffs_won="3" faceoffs_lost="3" shots="1" goals="0" missed_shots="0" assists="0" faceoffs="6" faceoff_win_pct="50.0"/>
<evenstrength faceoff_win_pct="40.5" missed_shots="7" goals="1" faceoffs_won="17" shots="26" faceoffs="42" faceoffs_lost="25" assists="2"/>
<penalty shots="0" goals="0" missed_shots="0"/>
</statistics>
<shootout shots="0" missed_shots="0" goals="0" shots_against="0" goals_against="0" saves="0" saves_pct="0"/>
<goaltending shots_against="33" goals_against="4" saves="29" saves_pct="0.879" total_shots_against="33" total_goals_against="4">
<powerplay shots_against="0" goals_against="0" saves="0" saves_pct="0"/>
<shorthanded shots_against="7" goals_against="0" saves="7" saves_pct="1.0"/>
<evenstrength goals_against="4" saves_pct="0.846" shots_against="26" saves="22"/>
<penalty shots_against="0" goals_against="0" saves="0" saves_pct="0"/>
<emptynet goals_against="0" shots_against="0">
<powerplay goals_against="0"/>
<shorthanded goals_against="0"/>
<evenstrength goals_against="0"/>
</emptynet>
</goaltending>
Here's an XPath 2.0 expression that should do what you asked, yielding a sequence of two elements:
(/game/team[#id = /game/#home_team]/statistics/#goals,
/game/team[#id = /game/#away_team]/statistics/#goals)
Credit to #Ian for sleuthing out the details of the question.
In XPath 1.0, you could concatenate string data from the two teams in whatever order you want:
concat(/game/team[#id = /game/#home_team]/statistics/#goals, ' ',
/game/team[#id = /game/#away_team]/statistics/#goals)
But as Ian said, you can't produce a nodeset with an order different from document order. (I don't think a nodeset has any intrinsic order at all... it's how it's processed that imposes an order.)
Update:
As Ian pointed out, your XML data is in a namespace, thanks to the default namespace declaration on <game>. Since you said that "/game/team/statistics/#goals gives me the data", I'm assuming that you've already taken care of this aspect of the problem, perhaps by declaring the default namespace in your XPath execution environment.

XPath for overview values of emma report

I generate EMMA reports during my build, they look like this
<report>
<stats>
<packages value="110"/>
<classes value="1762"/>
<methods value="12617"/>
<srcfiles value="962"/>
<srclines value="61320"/>
</stats>
<data>
<all name="all classes">
<coverage type="class, %" value="2% (42/1762)"/>
<coverage type="method, %" value="2% (302/12617)"/>
<coverage type="block, %" value="3% (6849/258033)"/>
<coverage type="line, %" value="3% (1592.9/61320)"/>
I need to get the percentage from the value attributes of the /report/data/all/coverage nodes. Currently getting these:
Invalid XPath expression: "/report/data/all/coverage[starts-with(#type,'block')]#value": Unexpected '#'
Invalid XPath expression: "substring-before(/report/data/all/coverage[starts-with(#type,'block']#value,'%')": Expected: )
You are missing a forward slash from the XPath before the #value attribute. There is also a missing brackets in your starts-with function
Try the following
/report/data/all/coverage[starts-with(#type,'block')]/#value
substring-before(/report/data/all/coverage[starts-with(#type,'block')]/#value,'%')

Want to skip a tag and get by index

Given this XML:
<mets:mets>
<mets:fileSec>
<mets:fileGrp ID="fileGrp001" USE="image/dynamic">
<mets:file ID="filebib4112678_18760203_1_24_0001_m.jp2" MIMETYPE="image/jp2" SIZE="5308416"
CREATED="2009-11-10T00:00:00" USE="image/dynamic" ADMID="techMD001"
CHECKSUM="c07f516d77d8a5ca452775d489ffe78c" CHECKSUMTYPE="MD5">
<mets:FLocat LOCTYPE="URL" xlink:type="simple"
xlink:href="file:bib4112678_18760203_1_24_0001_m.jp2"/>
</mets:file>
<mets:file ID="filebib4112678_18760203_1_24_0002_m.jp2" MIMETYPE="image/jp2" SIZE="5308416"
CREATED="2009-11-10T00:00:00" USE="image/dynamic" ADMID="techMD002"
CHECKSUM="6497ceb7a8477fbe9ba4ff9e6e57999f" CHECKSUMTYPE="MD5">
<mets:FLocat LOCTYPE="URL" xlink:type="simple"
xlink:href="file:bib4112678_18760203_1_24_0002_m.jp2"/>
</mets:file>
</mets:fileGrp>
<mets:fileGrp ID="fileGrp002" USE="text/alto">
<mets:file ID="filebib4112678_18760203_1_24_0001_alto.xml" MIMETYPE="text/xml" SIZE="1114112"
CREATED="2009-11-10T00:00:00" USE="text/alto" ADMID="techMD005"
CHECKSUM="e391852693f78d2eb024caf6dbdb97c6" CHECKSUMTYPE="MD5">
<mets:FLocat LOCTYPE="URL" xlink:type="simple"
xlink:href="file:bib4112678_18760203_1_24_0001_alto.xml"/>
</mets:file>
<mets:file ID="filebib4112678_18760203_1_24_0002_alto.xml" MIMETYPE="text/xml" SIZE="1114112"
CREATED="2009-11-10T00:00:00" USE="text/alto" ADMID="techMD006"
CHECKSUM="e391852693f78d2eb024caf6dbdb97c6" CHECKSUMTYPE="MD5">
<mets:FLocat LOCTYPE="URL" xlink:type="simple"
xlink:href="file:bib4112678_18760203_1_24_0002_alto.xml"/>
</mets:file>
</mets:fileGrp>
</mets:fileSec>
</mets:mets>
This expression :
/mets/fileSec/fileGrp[2]/file[2]/#ADMID
gives the result "techMD006"
However, I would like to get the same result using something like this expression/query:
/mets/fileSec//file[4]/#ADMID
I.e I don't want to bother about the fileGrp element, since it makes things more complicated. Unfortunately the expression above didn't work..
Does anyone know how to make such an expression?
thanx!
Your expression retrieves all file elements that are a descendant of /mets/fileSec and are the fourth child of their parent:
/mets/fileSec//file[4]/#ADMID
But you have no such elements. What you want is to retrieve all file elements that are a descendant of /mets/fileSec and then take the fourth one. Use this:
(/mets/fileSec//file)[4]/#ADMID

Resources