XPath for overview values of emma report - xpath

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,'%')

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}]'

how to read the data from XML with spaces using oracle

I want to read the data from passage_para tag, after passage_para I have 2 spaces before the expression tag and after the expression tag I have one more space, etc. When I use extract function to get the passage_para tag from the XMLTYPE column it is eliminating all the spaces.
<?xml version="1.0" encoding="UTF-8"?> <item> <information number="sdjsadh" > <response_direction delivery_mode="xcs"> <dparagraph>test</dparagraph> </response_direction> </information> <i_content> <stimulus_reference> <passage> <prose style="1"> <passage_para> <expression> <math xmlns="Math" xmlns:xlink="xlink" display="inline" overflow="scroll"> <mr> <mi>z</mi> <mo>></mo> <mn>0</mn> </mr> </math> </expression> </passage_para> </prose> </passage> </stimulus_reference> </i_content> </item>
which I don't want because it is taking out the spaces. The desired output I need is " z > 0 ".
Note: Between the passage_para tag the child nodes may change, they are not going to be the same.

XPath : Number of Occurrence of an element

How do i get the output for first tag starting with "<intro><longtitle" as 1 . Second tag "<intro><longtitle>" as 2 and so on using XPATH. The need is to get the occurrence of the element .
<intro><longtitle> Demo </longtitle>
..
..
<intro><longtitle> Test </longtitle>
.
.
<intro><longtitle> Demo Test</longtitle>
Regards,
Sri
For your XML corrected to be well-formed,
<?xml version="1.0" encoding="UTF-8"?>
<r>
<intro>
<longtitle> Demo </longtitle>
</intro>
<intro>
<longtitle> Test </longtitle>
</intro>
<intro>
<longtitle> Demo Test </longtitle>
</intro>
</r>
you can specify the intro element with a Test string value of longtitle:
//intro[normalize-space(longtitle) = 'Test']
and count the preceding siblings,
count(//intro[normalize-space(longtitle) = 'Test']/preceding-sibling::intro) + 1
to determine that the selected intro is the second sibling:
2

How can I get the texts by calling the attribute?

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?

CSV to XML conversion using MFL

I have an CSV file like:
1234|abc|val1=12;val2=13;val3=14
1235|xyz|val1=15;val2=16;val3=18
I need to convert it into XML using mfl file.
This is my approach:
<StructFormat name='player' delimOptional='n' repeat='*'>
<FieldFormat name='FieldID' type='String' delimRef='' delim='|' dataDelim='"' delimOptional='n' optional='n' codepage='UTF-8'/>
<FieldFormat name='playerName' type='String' delimRef='' delim='|' dataDelim='"' delimOptional='n' optional='n' codepage='UTF-8'/>
<StructFormat name='extraList' delim='|' delimOptional='n' optional='y'>
<FieldFormat name='extra' type='String' delimRef='' delim='|' delimOptional='n' optional='y' codepage='UTF-8' repeat='*'/>
</StructFormat>
</StructFormat>
I don't know how to implement unlimited amount of couples: val1=12 assigned to each player.
Any help? Thank you!
Appears to be generated by tool, check used wizard for
Group Occurrence -> Repeat Delimiter -> Select this option to indicate that the group will repeat until the specified delimiter is encountered.
as per http://docs.oracle.com/cd/E13214_01/wli/docs70/diuser/fmtdef.htm - dated but still ok

Resources