Property Transfer in SOAPUI. How to transfer data with specific parameters? - web-services

I have such kind of response:
<s:Envelope xmlns:s="http://.....">
<s:Body>
<GetHistoricalMeterReadingsByEanResponse xmlns="....">
<GetHistoricalMeterReadingsByEanResult xmlns:a="....." xmlns:i="http://....">
<Header xmlns=".....">
<HasException>false</HasException>
<Message/>
</Header>
<a:HistoricalReadingSet>
<a:HistoricalMeterReadingSet>
<a:EanId>111425200000005564</a:EanId>
<a:HistoricalReadings>
<a:HistoricalMeterReading>
<a:ClientReadingDate i:nil="true"/>
<a:EanId>111425200000005564</a:EanId>
<a:EdsnMeterId>3523525</a:EdsnMeterId>
<a:EnergyProductType>ELK</a:EnergyProductType>
<a:MeterReadingId>1842643</a:MeterReadingId>
<a:Mutation>
<a:Consumer i:nil="true"/>
<a:DossierId i:nil="true"/>
<a:Initiator i:nil="true"/>
<a:MarketEvent>Historical</a:MarketEvent>
<a:MarketEventDate>2015-01-28T00:00:00</a:MarketEventDate>
</a:Mutation>
<a:NrOfRegisters>2</a:NrOfRegisters>
<a:ProcessId i:nil="true"/>
<a:ReadingSource>Customer_TMR</a:ReadingSource>
<a:RegisterReadings>
<a:RegisterReading>
<a:MeasureUnit>KWH</a:MeasureUnit>
<a:MeteringDirection>LVR</a:MeteringDirection>
<a:NrOfDigits>6</a:NrOfDigits>
<a:TariffType>L</a:TariffType>
<a:Value>1345</a:Value>
</a:RegisterReading>
<a:RegisterReading>
<a:MeasureUnit>KWH</a:MeasureUnit>
<a:MeteringDirection>LVR</a:MeteringDirection>
<a:NrOfDigits>6</a:NrOfDigits>
<a:TariffType>N</a:TariffType>
<a:Value>2345</a:Value>
</a:RegisterReading>
</a:RegisterReadings>
<a:Status>Accepted</a:Status>
<a:BudgetCanStartSettlement>false</a:BudgetCanStartSettlement>
<a:CanStartDispute>false</a:CanStartDispute>
<a:OtherSupplierCanStartSettlement>false</a:OtherSupplierCanStartSettlement>
</a:HistoricalMeterReading>
<a:HistoricalMeterReading>
<a:ClientReadingDate i:nil="true"/>
<a:EanId>111425200000005564</a:EanId>
<a:EdsnMeterId>3523525</a:EdsnMeterId>
<a:EnergyProductType>ELK</a:EnergyProductType>
<a:MeterReadingId>1842645</a:MeterReadingId>
<a:Mutation>
<a:Consumer>8714252018141</a:Consumer>
<a:DossierId>23074990</a:DossierId>
<a:Initiator>1114252018146</a:Initiator>
<a:MarketEvent>Periodic</a:MarketEvent>
<a:MarketEventDate>2015-09-14T00:00:00</a:MarketEventDate>
</a:Mutation>
<a:NrOfRegisters>2</a:NrOfRegisters>
<a:ProcessId i:nil="true"/>
<a:ReadingSource>Customer_EDSN</a:ReadingSource>
<a:RegisterReadings>
<a:RegisterReading>
<a:MeasureUnit>KWH</a:MeasureUnit>
<a:MeteringDirection>LVR</a:MeteringDirection>
<a:NrOfDigits>6</a:NrOfDigits>
<a:TariffType>L</a:TariffType>
<a:Value>3000</a:Value>
</a:RegisterReading>
<a:RegisterReading>
<a:MeasureUnit>KWH</a:MeasureUnit>
<a:MeteringDirection>LVR</a:MeteringDirection>
<a:NrOfDigits>6</a:NrOfDigits>
<a:TariffType>N</a:TariffType>
<a:Value>4000</a:Value>
</a:RegisterReading>
</a:RegisterReadings>
<a:Status>Accepted</a:Status>
<a:BudgetCanStartSettlement>false</a:BudgetCanStartSettlement>
<a:CanStartDispute>true</a:CanStartDispute>
<a:OtherSupplierCanStartSettlement>true</a:OtherSupplierCanStartSettlement>
</a:HistoricalMeterReading>
</a:HistoricalReadings>
</a:HistoricalMeterReadingSet>
</a:HistoricalReadingSet>
</GetHistoricalMeterReadingsByEanResult>
</GetHistoricalMeterReadingsByEanResponse>
The problem is: I use this response in oreder to find there an item with 3value field = true. I need such item for the next request method.
I tried smth like this but it didn't work:
<a:HistoricalReadingSet//a:HistoricalMeterReadingSet//a:HistoricalReadings//a:HistoricalMeterReading a="http://....">
{
for $x in //a:HistoricalReadingSet//a:HistoricalMeterReadingSet//a:HistoricalReadings//a:HistoricalMeterReading
where $x/a:HistoricalReadingSet//a:HistoricalMeterReadingSet//a:HistoricalReadings//a:HistoricalMeterReading//a:CanStartDispute/text() = 'true'
return $x
}
</a:HistoricalReadingSet//a:HistoricalMeterReadingSet//a:HistoricalReadings//a:HistoricalMeterReading>
What is wrong? How would you do it?

In Xml the numbers are not alloweds as a first character of tag names, besides your xml is not well formed since some tags are not correctly closed. Try first correcting your xml.
<a:SetOfItems>
<a:Item>
<a:Id>1</a:Id>
<a:firstValue>12121212</a:firstValue>
<a:secondValue>sdfhjfsdf</a:secondValue>
<a:thirdValue>false</a:thirdValue>
</a:Item>
<a:Item>
<a:Id>2</a:Id>
<a:firstValue>12121212</a:firstValue>
<a:secondValue>sdfhjfsdf</a:secondValue>
<a:thirdValue>true</a:thirdValue>
</a:Item>
</a:SetOfItems>
Then to add your XQuery as a property transfer to select only the <a:Item> elements where <a:thirdValue> has a text value true you can use the follow expression:
<a:SetOfItems xmlns:a="blabla">
{
for $x in //*:Item
where $x/*:thirdValue/text() = 'true'
return $x
}
</a:SetOfItems>
Note the use of * wildcard to refer any namespace.
Applying this XQuery to your XML you will get:
<a:SetOfItems xmlns:a="blabla">
<a:Item>
<a:Id>2</a:Id>
<a:firstValue>12121212</a:firstValue>
<a:secondValue>sdfhjfsdf</a:secondValue>
<a:thirdValue>true</a:thirdValue>
</a:Item>
</a:SetOfItems>
EDIT BASED ON THE QUESTION UPDATE
I think that there are various things wrong in your XQuery, the follow XQuery works for your xml:
<a:HistoricalReadingSet xmlns:a="http://a">
{
for $x in //*:HistoricalReadingSet/*:HistoricalMeterReadingSet
where $x/*:HistoricalReadings/*:HistoricalMeterReading/*:CanStartDispute/text() = 'true'
return $x
}
</a:HistoricalReadingSet>
It's generate the follow result:
<a:HistoricalReadingSet xmlns:a="http://a">
<a:HistoricalMeterReadingSet xmlns:a="http://a" xmlns:i="http://i" xmlns="http://b" xmlns:s="http://soap">
<a:EanId>111425200000005564</a:EanId>
<a:HistoricalReadings>
<a:HistoricalMeterReading>
<a:ClientReadingDate i:nil="true"/>
<a:EanId>111425200000005564</a:EanId>
<a:EdsnMeterId>3523525</a:EdsnMeterId>
<a:EnergyProductType>ELK</a:EnergyProductType>
<a:MeterReadingId>1842643</a:MeterReadingId>
<a:Mutation>
<a:Consumer i:nil="true"/>
<a:DossierId i:nil="true"/>
<a:Initiator i:nil="true"/>
<a:MarketEvent>Historical</a:MarketEvent>
<a:MarketEventDate>2015-01-28T00:00:00</a:MarketEventDate>
</a:Mutation>
<a:NrOfRegisters>2</a:NrOfRegisters>
<a:ProcessId i:nil="true"/>
<a:ReadingSource>Customer_TMR</a:ReadingSource>
<a:RegisterReadings>
<a:RegisterReading>
<a:MeasureUnit>KWH</a:MeasureUnit>
<a:MeteringDirection>LVR</a:MeteringDirection>
<a:NrOfDigits>6</a:NrOfDigits>
<a:TariffType>L</a:TariffType>
<a:Value>1345</a:Value>
</a:RegisterReading>
<a:RegisterReading>
<a:MeasureUnit>KWH</a:MeasureUnit>
<a:MeteringDirection>LVR</a:MeteringDirection>
<a:NrOfDigits>6</a:NrOfDigits>
<a:TariffType>N</a:TariffType>
<a:Value>2345</a:Value>
</a:RegisterReading>
</a:RegisterReadings>
<a:Status>Accepted</a:Status>
<a:BudgetCanStartSettlement>false</a:BudgetCanStartSettlement>
<a:CanStartDispute>false</a:CanStartDispute>
<a:OtherSupplierCanStartSettlement>false</a:OtherSupplierCanStartSettlement>
</a:HistoricalMeterReading>
<a:HistoricalMeterReading>
<a:ClientReadingDate i:nil="true"/>
<a:EanId>111425200000005564</a:EanId>
<a:EdsnMeterId>3523525</a:EdsnMeterId>
<a:EnergyProductType>ELK</a:EnergyProductType>
<a:MeterReadingId>1842645</a:MeterReadingId>
<a:Mutation>
<a:Consumer>8714252018141</a:Consumer>
<a:DossierId>23074990</a:DossierId>
<a:Initiator>1114252018146</a:Initiator>
<a:MarketEvent>Periodic</a:MarketEvent>
<a:MarketEventDate>2015-09-14T00:00:00</a:MarketEventDate>
</a:Mutation>
<a:NrOfRegisters>2</a:NrOfRegisters>
<a:ProcessId i:nil="true"/>
<a:ReadingSource>Customer_EDSN</a:ReadingSource>
<a:RegisterReadings>
<a:RegisterReading>
<a:MeasureUnit>KWH</a:MeasureUnit>
<a:MeteringDirection>LVR</a:MeteringDirection>
<a:NrOfDigits>6</a:NrOfDigits>
<a:TariffType>L</a:TariffType>
<a:Value>3000</a:Value>
</a:RegisterReading>
<a:RegisterReading>
<a:MeasureUnit>KWH</a:MeasureUnit>
<a:MeteringDirection>LVR</a:MeteringDirection>
<a:NrOfDigits>6</a:NrOfDigits>
<a:TariffType>N</a:TariffType>
<a:Value>4000</a:Value>
</a:RegisterReading>
</a:RegisterReadings>
<a:Status>Accepted</a:Status>
<a:BudgetCanStartSettlement>false</a:BudgetCanStartSettlement>
<a:CanStartDispute>true</a:CanStartDispute>
<a:OtherSupplierCanStartSettlement>true</a:OtherSupplierCanStartSettlement>
</a:HistoricalMeterReading>
</a:HistoricalReadings>
</a:HistoricalMeterReadingSet>
</a:HistoricalReadingSet>
EDIT BASED ON COMMENT
If you only want to take the <MeterReadingId> value where <CanStartDispute> sibling is true, you can simply use the follow XPath instead of XQuery:
//*:HistoricalReadingSet/*:HistoricalMeterReadingSet/*:HistoricalReadings/*:HistoricalMeterReading/*:MeterReadingId[../*:CanStartDispute/text() = 'true']
Hope it helps,

Related

XSLT - select a node from a complex xml file

I have an XML file below where I need to get the text inside of the <Description> tag under the <Checklist> tag where the <Sequence> tag has the text 40. How to achieve it?
<?xml version="1.0" encoding="UTF-8"?>
<SyncMaintenanceOrder>
<DataArea>
<MaintenanceOrder>
<MaintenanceOrderHeader>
<DocumentID>
<ID accountingEntity="AT">1105442</ID>
</DocumentID>
<Description>Routine Bridge Inspection - S6</Description>
<PriorityCode>2</PriorityCode>
<ReportedDateTime>2020-04-29T20:21:27Z</ReportedDateTime>
</MaintenanceOrderHeader>
<MaintenanceOrderLine>
<LineNumber>10</LineNumber>
<RemainingDuration>PT8H0M0S</RemainingDuration>
<ActivityDeferredIndicator>false</ActivityDeferredIndicator>
<UserArea>
<EamCheckListInfo>
<CheckList>
<CheckListItem>
<Sequence>40</Sequence>
<Description>Half joints (Superstructure elements)</Description>
</CheckListItem>
<CheckListItem>
<Sequence>160</Sequence>
<Description>Substructure drainage (Durability elements)</Description>
</CheckListItem>
<CheckListItem>
<Sequence>60</Sequence>
<Description>Parapet beam or cantilever (Superstructure elements)</Description>
</CheckListItem>
</CheckList>
</EamCheckListInfo>
</UserArea>
</MaintenanceOrderLine>
</MaintenanceOrder>
</DataArea>
</SyncMaintenanceOrder>
I need sample of an XSLT code for selecting only the text node described above.
I'm not sure I really get your question.
This will print the Description of the CheckListItem which has a Sequence of 40:
<xsl:value-of select="//CheckListItem/Sequence[text()='40']/../Description"/>
Try it here: https://xsltfiddle.liberty-development.net/ehVZvvZ
Try the below code
<xsl:value-of select="*[local-name(.)='SyncMaintenanceOrder']/*[local-name(.)='DataArea']/*[local-name(.)='MaintenanceOrder']/*[local-name(.)='MaintenanceOrderLine']/*[local-name(.)='UserArea']/*[local-name(.)='EamCheckListInfo']/*[local-name(.)='CheckList']/*[local-name(.)='CheckListItem']/*[local-name(.)='Sequence'][text() = '40']/../*[local-name(.)='Description']" />

How can I replace special characters with Schematron

How can I replace special characters and spaces in an attribute? I tried various regular expressions but none of them worked as aspected.
<pattern id="setElementId">
<rule context="*[contains(#class, ' domain/element ') and boolean(#id)]">
<!-- Works, replaces 'a' -->
<let name="reqId" value="replace(#id, '[a]', '')"/>
<assert test="#id=$reqId" sqf:fix="setId">
The attribute "id" must comply with the given rules: "<value-of select="$reqId"/>"
</assert>
<sqf:fix id="setId">
<sqf:description>
<sqf:title>Set "id" to "<value-of select="$reqId"/>"</sqf:title>
<sqf:p>Set "id" to the calculated value.</sqf:p>
</sqf:description>
<sqf:replace match="#id" node-type="attribute" target="id" select="$reqId"/>
</sqf:fix>
</rule>
</pattern>
Your last efforts weren't remorsed I think.
Check the CSS codings:
Style {template.css}
Remove that from the end user's example and you'll have your answer!
<sqf:replace match="#id" node-type="attribute" target="id" select="$reqId"/>
</sqf:fix>
That didn't return the side value.
I answer my own question using the suggested replace statement by sergioFC.
<pattern id="setElementId">
<rule context="*[contains(#class, ' topic/dlentry ') and boolean(#id) and descendant-or-self::*[contains(#class, ' ui-d/uicontrol ')]]" role="info">
<let name="reqId" value="descendant-or-self::*[contains(#class, ' ui-d/uicontrol ')]"/>
<let name="reqId" value="replace($reqId, 'ä', 'ae')"/>
<let name="reqId" value="replace($reqId, 'ö', 'oe')"/>
<let name="reqId" value="replace($reqId, 'ü', 'ue')"/>
<let name="reqId" value="replace($reqId, 'Ä', 'ue')"/>
<let name="reqId" value="replace($reqId, 'Ö', 'ue')"/>
<let name="reqId" value="replace($reqId, 'Ü', 'ue')"/>
<let name="reqId" value="replace($reqId, 'ß', 'ss')"/>
<let name="reqId" value="replace($reqId, '[^0-9a-zA-Z]', '')"/>
<assert test="#id=$reqId" sqf:fix="setId" role="warning">
The attribute "id" must comply with the given rules: "<value-of select="$reqId"/>"
</assert>
<sqf:fix id="setId">
<sqf:description>
<sqf:title>Set "id" to "<value-of select="$reqId"/>"</sqf:title>
<sqf:p>Set "id" to the calculated value.</sqf:p>
</sqf:description>
<sqf:replace match="#id" node-type="attribute" target="id" select="$reqId"/>
</sqf:fix>
</rule>
</pattern>
Using this pattern, I can generate id attributes for <dlentry> elements based on the value of the descendant <uicontrol> element.

Regular expression in java to extract URl from HTML

I am new to regexes. I need help.
My HTML source is
<img src ="planets.gif" width="145" height="126" alt="Planets" usemap ="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="http://www.sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="http://www.mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="http://www.www.venus.htm" alt="Venus">
</map>
I’m trying to extract all href links out like http://www.google.com.
kindly help.
My Regex is
"href=[\\\"\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?[\\\"\\']"
it wil extract like href="http://www.google.com"
But I need only link http://www.google.com without href=
Please use a XML-parser for this kind of stuff.

XSL - Display XML tags based on parameter from PHP

Ive got a problem displaying my desired XML tags based on an parameter. I'm fairly new to this.
XML Example:
<car name="Toyota">
<model nr="123" yeardate="2010">
<owner ssn="123456789" name="Tom"/>
<owned years="0" months="6"/>
</model>
</car>
<car name="Volvo">
<model nr="222" yeardate="2009">
<owner ssn="345364774" name="John"/>
<owned years="0" months="8"/>
</model>
</car>
<car name="Fiat">
<model nr="333" yeardate="2010">
<owned years="0" months="0"/>
</model>
</car>
The problem is that I want to be able to choose the car that is displayed BASED on an HTML form I made in my PHP document. So, I made a form in PHP, sent the value of POST back to my XSL document and now I want to display the car based on this parameter value. Also, notice that the car Fiat does not have an owner. I am able to get the value of POST in my XSL document, but I'm not sure how I go about using this parameter.
What I imagine this turning in to:
Lets say that Toyota is choosen in the form,
car name=Toyota
model nr=123 yeardate=2010
owner ssn=123456789 name=tom
owned years=0 months=6
I want to include the tag name as well as all the attributes.
If you're using PHP, maybe you don't need XSL. Have a look at SimpleXML.
<?php
$xmlString = '<root>
<car name="Toyota">
<model nr="123" yeardate="2010">
<owner ssn="123456789" name="Tom"/>
<owned years="0" months="6"/>
</model>
</car>
<car name="Fiat">
<model nr="333" yeardate="2010">
<owned years="0" months="0"/>
</model>
</car>
</root>';
$xml = new SimpleXMLElement($xmlString);
foreach ($xml->children() as $second_gen) {
if ( (string) $second_gen['name'] == "Toyota") {
echo $second_gen->asXML();
}
}
?>

Sharepoint batch for MultiChoice field value insertion

So i have a problem regarding usage of sharepoint list webservices.
I need to get the syntax right for Sharepoint batch script for insertion of new items.
Everyhing works fine except multichoice field type.
I insert the data, but nomatter how i do it, it shows up on SP list item details OK, but when trying to edit item in SP, i see, that SP have taken the value i sent to this field as text string, and does not check the items i have saved as selected.
The script for now is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Batch OnError="Return">
<Method ID='1' Cmd='New'>
<Field Name='SecurityCheckpoints'>1st checkpoint;2nd checkpoint</Field>
</Method>
</Batch>
Definition for that field is like this:
<Field Type="MultiChoice"
DisplayName="Checkpoints allowed"
Required="TRUE"
FillInChoice="FALSE"
ID="{guid-guid-guid-guid-guid}"
SourceID="{guid-guid-guid-guid-guid}"
StaticName="SecurityCheckpoints"
Name="SecurityCheckpoints"
ColName="ntext2"
RowOrdinal="0"
Version="4">
<CHOICES>
<CHOICE>1st checkpoint</CHOICE>
<CHOICE>2nd checkpoint</CHOICE>
<CHOICE>3rd checkpoint</CHOICE>
</CHOICES>
<Default>1st checkpoint</Default>
</Field>
I have to implement something like custom UI for sharepoint in different-purpouse silverlight app, and so i am using my own webservice to be a proxy between SP and SL, i retrieve SP list definition and dinamicaly build UI controls, so user can fill in the forms.
How do i form the script, so items are selected(ticked) in the SP instead of SP saving them as just string value?
If I use script with only one item ("1st checkpoint"), SP processes it ok, it there is many, data is saved as text string?
What i am doing wrong? How do i correctly seperate multiple values?
I have searched high and low, but have not found example of SP update script, where multichoice sample is included.
Thank You in advance!
I found the sollution - it was too easy:
instead of seperating the choice values using semicolon ";", they had to be seperated using ";#", and putting it in front and in behind the whole list.
So rather than using this:
1st checkpoint;2nd checkpoint
<?xml version="1.0" encoding="UTF-8"?>
<Batch OnError="Return">
<Method ID='1' Cmd='New'>
<Field Name='SecurityCheckpoints'>1st checkpoint;2nd checkpoint</Field>
</Method>
</Batch>
It had to be done like this:
;#1st checkpoint;#2nd checkpoint;#
<?xml version="1.0" encoding="UTF-8"?>
<Batch OnError="Return">
<Method ID='1' Cmd='New'>
<Field Name='SecurityCheckpoints'>;#1st checkpoint;#2nd checkpoint;#</Field>
</Method>
</Batch>
PS:I dont know was it correct way to do this, but I answered my own question. Just for others to know.
I run code below successfully.
<?xml version="1.0" encoding="UTF-8"?><ows:Batch OnError="Return">
<Method ID="0"><SetList>3933c528-5747-4fc7-bdec-6465294997dd</SetList>
<SetVar Name="Cmd">Save</SetVar>
<SetVar Name="ID">New</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#Temp_UNID">8D8DE35CFFE9EEEAC12570920052A8FD</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#Title"> - Birch Data Exchange Specification</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_DocNum">8AL020210178ZZASB</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_Phase"></SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_Author">Jerome BOURGER</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_ServicesOri"> </SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_Type">;#3 - Quality Plan;#Objectives;#Progress Plan;#Follow-up;#Reports;#</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_Keywords"></SetVar> </Method></ows:Batch>