can't extract value from xpath-extract using mule variables - xpath

I have a set LocationProperties variable as its Location-465697646-800339871 value. Based on the value of a variable, I want to select a node in the payload.
Mule 3:
xpath3('//DTOLocation[#id=\'' + flowVars.LocationProperties.LocationRef + '\'][1]/DTOLocationDetail[#DetailTypeCd=\'CommercialPropertyLocationDetail\'][1]/#ProtectionClassCd',flowVars.domPayload)
xpath3('//DTOLocation[#id=' + flowVars.LocationProperties.LocationRef + '][1]/#LocationCounterNumber',flowVars.domPayload)
Mule 4 flow:
<flow name="var_xpath_testFlow" doc:id="406270fb-17e7-48e9-a33a-f7a0197f8e05" >
<http:listener doc:name="Listener" doc:id="662f2277-859f-4516-974b-de7cceeb5b40" config-ref="HTTP_Listener_config" path="/vartest"/>
<set-variable value="#[payload]" doc:name="Set domPayload" doc:id="2495ac98-b976-41e0-9dcf-398574e54ffa" variableName="domPayload"/>
<set-variable value="Location-465697646-800339871" doc:name="Set Variable" doc:id="12370458-bb32-4709-b509-acc1e5f50b94" variableName="LocationProperties"/>
<xml-module:xpath-extract xpath="#["/DTOApplication/DTOLocation[#id='" ++ vars.LocationProperties ++ "'][1]"/DTOLocationDetail[#DetailTypeCd='CommercialPropertyLocationDetail'][1]/#ProtectionClassCd]" target="xvalue1" config-ref="XML_Config"/>
<xml-module:xpath-extract xpath="#["/DTOApplication/DTOLocation[#id='" ++ vars.LocationProperties ++ "'][1]"/#LocationCounterNumber]" config-ref="XML_Config" target="xvalue2"/>
<logger level="INFO" doc:name="Logger" doc:id="f495b0bf-f8cb-43be-b4d9-d069758e4028" message="#[vars.xvalue]"/>
</flow>
Input payload: https://github.com/Manikandan99/rate-dtostep/blob/master/request.xml
Expected output is the variable :
xvalue1 returns 3,
xvalue2 returns 1.
If I give values directly in xpath, it's work.
When I'm trying to use variables inside an xpath,it throws error like : https://github.com/Manikandan99/rate-dtostep/blob/master/xapth_error.txt
How to extract value using variables in XPath Mule 4?

The error is because you have not added double code correctly in the expression of XPath
I have done some corrections as below
<flow name="var_xpath_testFlow" doc:id="406270fb-17e7-48e9-a33a-f7a0197f8e05" >
<http:listener doc:name="Listener" doc:id="662f2277-859f-4516-974b-de7cceeb5b40" config-ref="HTTP_Listener_config" path="/vartest"/>
<set-variable value="#[payload]" doc:name="Set domPayload" doc:id="2495ac98-b976-41e0-9dcf-398574e54ffa" variableName="domPayload"/>
<set-variable value="Location-465697646-800339871" doc:name="Set Variable" doc:id="12370458-bb32-4709-b509-acc1e5f50b94" variableName="LocationProperties"/>
<xml-module:xpath-extract doc:name="Xpath extract" doc:id="4a8ce1ed-3c1c-48f7-95dd-664654c6a66b" xpath="#["/DTOApplication/DTOLocation[#id='" ++ vars.LocationProperties ++ "'][1]/DTOLocationDetail[#DetailTypeCd='CommercialPropertyLocationDetail'][1]/#ProtectionClassCd"]"/>
<xml-module:xpath-extract doc:name="Xpath extract" doc:id="6287299e-aae5-411b-b6d5-936e6c6be5fb" xpath="#["/DTOApplication/DTOLocation[#id='" ++ vars.LocationProperties ++ "'][1]/#LocationCounterNumber"]"/>
<logger level="INFO" doc:name="Logger" doc:id="f495b0bf-f8cb-43be-b4d9-d069758e4028" message="#[vars.xvalue]"/>
</flow>
With this, your error will get resolved, which is mentioned in your question. Also, I am not sure why are you setting the payload initially in a variable called domPayload, because you are not using it. Please look into that
as per our discussion in comments, for your expected output use below dataweave code just after second Xpath extractor
%dw 2.0
output application/json
---
(vars.xvalue1 default [] ++ vars.xvalue2 default []) joinBy ","
the o/p will be:- "3,1"

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 register two moduleType to VeinsInetManager?

I used SUMO to move vehicles and bus nodes on a four-lane road. The source code of my route file is as follows:
<routes>
<vType id="normal_car" vClass="passenger" maxSpeed="50" speedFactor="0.9" speedDev="0.2" sigma="0.5"/>
<vType id="mobile_rsu" vClass="bus" maxSpeed="30" speedFactor="1.1" speedDev="0.1" sigma="0.5"/>
<flow id="normal_car_flow" type="normal_car" begin="0" end="3500" number="500" from="edge0" to="edge2" departPos="random" departLane="random"/>
<flow id="mobile_rsu_flow" type="mobile_rsu" begin="0" end="5000" number="100" from="edge0" to="edge2" departPos="random" departLane="random"/>
</routes>
I have created a submodule for each node in Scenario.ned.
car[0] : Car
{
parameters:
#display("p=100,390;is=s");
}
mrsu[0] : mRSU
{
parameters:
#display("p=200,390;is=s");
}
I tried to register the mobile node in omnetpp.ini as follows: (Also I'm using VeinsInetManager.)
*.veinsManager.moduleType = "normal_car=org.car2x.veins.nodes.Car mobile_rsu=org.car2x.veins.nodes.mRSU"
*.veinsManager.moduleName = "normal_car=Car mobile_rsu=mRSU"
*.veinsManager.launchConfig = xmldoc("highway.launchd.xml")
*.veinsManager.host = "localhost"
*.veinsManager.port = 9999
*.veinsManager.autoShutdown = true
*.veinsManager.updateInterval = 1s
However, the following error occurs when running the simulation. How should I fix it?
Keys of mappings of moduleType and moduleName are not the same..
I solved the problem.
First of all, I applied this link to my problem.
Using my question, how to register 2 or more nodes in moduleType is as follows.
<routes>
<vType id="normal_car" vClass="passenger" maxSpeed="50" speedFactor="0.9" speedDev="0.2" sigma="0.5"/>
<vType id="mobile_rsu" vClass="bus" maxSpeed="30" speedFactor="1.1" speedDev="0.1" sigma="0.5"/>
<flow id="normal_car_flow" type="normal_car" begin="0" end="3500" number="500" from="edge0" to="edge2" departPos="random" departLane="random"/>
<flow id="mobile_rsu_flow" type="mobile_rsu" begin="0" end="5000" number="100" from="edge0" to="edge2" departPos="random" departLane="random"/>
</routes>
You can apply the following to omnetpp.ini to recognize nodes in the simulation.
*.veinsManager.moduleType = "mobile_rsu=org.car2x.veins.nodes.mRSU *=org.car2x.veins.nodes.Car"
*.veinsManager.moduleName = "mobile_rsu=mRSU *=Car"
*.veinsManager.launchConfig = xmldoc("highway.launchd.xml")
*.veinsManager.host = "localhost"
*.veinsManager.port = 9999
*.veinsManager.autoShutdown = true
*.veinsManager.updateInterval = 1s
That's it!

How to validate XML against XSD in PHP

I have tried to validate my XML against XSD by following way.
<?php
$xml= new DOMDocument;
$xml->load(xml path);
if ($xml->schemaValidate(xsd path)) {print "valid.\n";} else {print "invalid.\n";}
?>
It gives me following error
DOMDocument::schemaValidate(): Element '{http://www.w3.org/2001/XMLSchema}attribute': The content is not valid. Expected is (annotation?).
To see the error detail I add the libxml_use_internal_errors(true); in validation code as you can see below.
<?php
libxml_use_internal_errors(true);
$xml= new DOMDocument;
$xml->load(xml path);
if ($xml->schemaValidate(xsd path)) {print "valid.\n";} else {print "invalid.\n";}
?>
After adding this I got following warning
Severity: Warning
Message: DOMDocument::schemaValidate(): Invalid Schema
I validated this xml online against my xsd and it is valid.However, in my php code it gives me error and I google these errors and it says the document could be invalid while I am sure the document is correct as I have validated it online. I am bit new in this so may be there is some mistake I am doing in validation code but unable to see.
Here is XML
<Application xmlns="NextGenMALI-Schema" Type="NewApplication">
<Identifier>1584928194</Identifier>
<SalesChannel SalesChannelType="Broker">
<Identifier>I12345</Identifier>
<CompanyName BusinessName="National Finance and Loans"/>
<PersonName>
<NameTitle Value="Mr"/>
<FirstName>Jonson</FirstName>
<Surname>Jonson</Surname>
</PersonName>
<RelatedEntityRef Type="crm_id">abc#yahoo.com</RelatedEntityRef>
<Email>abc#yahoo.com</Email>
</SalesChannel>
<SalesChannel SalesChannelDescription="BDM">
<Identifier/>
<PersonName>
<Surname/>
</PersonName>
</SalesChannel>
<Comment>Test comments.</Comment>
<PartySegment>
<Party Type="Applicant" PrimaryApplicant="Yes">
<Identifier>4</Identifier>
<Privacy AllowCreditCheck="Yes" AllowDirectMarketing="No" SignatureVerification="No" PointVerificationCompleted="No" ExistingCustomer="Yes" AllowThirdPartyDisclosure="Yes">
<PointVerification DocumentType="DriversLicenceAust" DocumentNumber="12345" NameOnDocument="Josie Ann Test" VersionSighted="Original" VerificationCategory="Primary" Photographic="Yes" NameVerified="Yes" AddressVerified="Yes" SignatureVerified="Yes" DOBVerified="Yes">
<PlaceOfIssue>
<City>NSW</City>
</PlaceOfIssue>
<EndDate>2014-11-28</EndDate>
</PointVerification>
<DocumentsSightedBy LoanWriter="No"/>
</Privacy>
<ResponsibleLend/>
<Person FirstHomeBuyer="Yes" CustomerOfLender="Yes" EmployeeOfLender="Yes" Director="No" PreviousName="Jones" Sex="Female">
<PersonName>
<NameTitle Value="Mr"/>
<FirstName>First Name</FirstName>
<OtherName>Middle Name</OtherName>
<Surname>Surname</Surname>
</PersonName>
<DateOfBirth>1993-02-01</DateOfBirth>
<MaritalStatus Status="Single" OtherDescription=""/>
<Dependent Age="2"/><Dependent Age="4"/>
<MothersMaidenName>Mother Maiden Name</MothersMaidenName>
<Residency PermanentInAustralia="Yes" Status="Citizen">
<Country ISO3166="AU"/>
</Residency>
<ContactDetails>
<AddressDetails Residential="Yes" Mailing="No" PriorAddress="No" PostSettlement="No" HousingStatus="Boarding">
<RelatedEntityRef>45e7815c217b8a</RelatedEntityRef>
<StartAndEndDates><StartDate>2019-04-04</StartDate></StartAndEndDates>
</AddressDetails><AddressDetails Residential="No" Mailing="No" PriorAddress="No" PostSettlement="No" HousingStatus="Caravan">
<RelatedEntityRef>45e7815c217ba4</RelatedEntityRef>
<StartAndEndDates><StartDate>2017-02-02</StartDate><EndDate>2017-02-02</EndDate></StartAndEndDates>
</AddressDetails><AddressDetails Residential="No" Mailing="No" PriorAddress="No" PostSettlement="No" HousingStatus="Renting">
<RelatedEntityRef>45e7815c217bac</RelatedEntityRef>
<StartAndEndDates><StartDate>2015-03-01</StartDate><EndDate>2015-03-01</EndDate></StartAndEndDates>
</AddressDetails>
<Email PreferredContactMethod="Yes">asd#yahoo.com</Email>
</ContactDetails>
<Employment OnProbation="No" PrimaryEmployment="Yes" PriorEmployment="No" Role="1112-11" RoleDescription="General Manager">
<PAYE Type="FullTime">
<RelatedEntityRef Type="RelatedParty">1097796810218</RelatedEntityRef>
</PAYE>
<StartAndEndDates>
<StartDate>2005-01-01</StartDate>
</StartAndEndDates>
<EmploymentIncome>
<ValueItem Value="10000">
<Identifier>IDARAHXC-Income</Identifier>
<Income Type="OtherIncome">
<Period Unit="Monthly">
<StartDate>2013-07-01</StartDate>
<EndDate>2014-06-30</EndDate>
</Period>
</Income>
</ValueItem>
</EmploymentIncome>
</Employment>
</Person>
</Party>
</PartySegment>
<AddressSegment>
<AddressWrapper>
<Identifier>45e7815c217b8a</Identifier>
<Address>
<StreetNo>8</StreetNo><Street Type="Street">Street</Street><City>Melbourne</City><State Name="VIC"/><Postcode>3000</Postcode>
<Country ISO3166="AU"/>
</Address>
</AddressWrapper>
<AddressWrapper>
<Identifier>45e7815c217ba4</Identifier>
<Address>
<StreetNo>4</StreetNo><Street Type="Street">Street</Street><City>Melville</City><State Name="WA"/><Postcode>6153</Postcode>
<Country ISO3166="AU"/>
</Address>
</AddressWrapper>
<AddressWrapper>
<Identifier>45e7815c217bac</Identifier>
<Address>
<StreetNo>7</StreetNo><Street Type="Street">Street</Street><City>Shire of Mornington Peninsula</City><State Name="VIC"/><Postcode>3941</Postcode>
<Country ISO3166="AU"/>
</Address>
</AddressWrapper>
</AddressSegment>
<FinancialSegment NoOtherAssets="No" NoLiabilities="No" NoIncome="No">
<ValueItem Value="41000">
<Identifier>1097796822609</Identifier>
<OwnedByAllApplicants/>
<Asset Class="CurrentSecurity" SecurityType="RegisteredMortgage">
<RealEstate Transaction="Purchasing" PrimarySecurity="Yes" PropertyPrimaryPurpose="OwnerOccupied" ApprovalInPrinciple="No" Status="Established" Holding="Sole">
<Residential WillOwn3UnitsInComplex="No" WillOwn25PercentOfComplex="No" OffThePlan="No" Type="FullyDetachedHouse"/>
<EstimatedValue>41000</EstimatedValue>
<ContractPrice LicencedRealEstateAgentContract="No" ContractPriceAmount="41000"/>
<VisitContact Type="Customer"/>
<Location>
<RelatedEntityRef>1415066564285</RelatedEntityRef>
<Title TitleType="Torrens" TenureType="Freehold"/>
</Location>
</RealEstate>
</Asset>
</ValueItem>
</FinancialSegment>
<RelatedPartySegment>
<RelatedParty RelPartyType="Lender">
<Identifier>1097796817156</Identifier>
<CompanyName BusinessName="AMP"/>
</RelatedParty>
</RelatedPartySegment>
<LoanDetailSegment>
<LoanDetails>
<Identifier>1097796802265</Identifier>
<EstimatedSettlement>2014-11-28</EstimatedSettlement>
<LoanPurpose PrimaryPurpose="OwnerOccupied" OwnerBuilderApplication="No">
<LendingPurposeCode ABSCode="ABS-125" PurposeAmount="0.0" Description="Affinity Fixed Rate, 1 Year (Investment)"/>
</LoanPurpose>
<LoanPortion ProductName="Affinity Fixed Rate, 1 Year (Investment)" ProductCode="AFFR1I" StatementCycle="Monthly" PackageName="">
<Identifier>1097796802265-1</Identifier>
<LoanTerm Units="Years" Type="TotalTerm">30</LoanTerm>
<LoanTerm Units="Years" Type="Variable" PaymentType="PrincipalAndInterest"/>
<AmountRequested Amount="41315" BaseAmount="41315"/>
<PaymentPeriod Payments="0.0">
<Period Unit="Monthly"/>
</PaymentPeriod>
</LoanPortion>
</LoanDetails>
<Representation Self="No">
<NominatedRepresentation>
<RelatedEntityRef>1415066458059</RelatedEntityRef>
</NominatedRepresentation>
</Representation>
</LoanDetailSegment>
<CrossSellSegment Enabled="true"/>
</Application>
<!-- NGPH: 237119.297 -->
Please find XSD here (Word limit exceeds so I had to upload it to share with you)
https://easyupload.io/qifnk1
password: myxsd

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.

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?

Resources