XPath Get Value based on sibling value - with namespace
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
There are lots of answers with no namespaces involved but I'm having trouble with the namespace.
Here's the xml doc:
<GetServiceRequestDetailsResponse xmlns="http://lcc.catscrm">
<GetServiceRequestDetailsResult xmlns:a="http://schemas.datacontract.org/2004/07/LCC.CATS.CRM.WCF.Model" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:AltRefs>
<a:AltRefModel>
<a:Name>UTRN</a:Name>
<a:TypeId>7577</a:TypeId>
<a:Value>9024930</a:Value>
</a:AltRefModel>
</a:AltRefs>
<a:Customer>
<a:Address>
<a:Address1>5</a:Address1>
<a:Address2>Random</a:Address2>
<a:County>West Yorks</a:County>
<a:NumberName>5</a:NumberName>
<a:Postcode>L1</a:Postcode>
<a:TownCity>London</a:TownCity>
<a:UPRN i:nil="true"/>
</a:Address>
<a:AltRefs/>
<a:ContactTransports>
<a:ContactTransport>
<a:Name>MobileNumber</a:Name>
<a:TypeId>3</a:TypeId>
<a:Value>08965</a:Value>
</a:ContactTransport>
<a:ContactTransport>
<a:Name>Email</a:Name>
<a:TypeId>1</a:TypeId>
<a:Value>a@b.com</a:Value>
</a:ContactTransport>
</a:ContactTransports>
<a:CustomerUPRN i:nil="true"/>
<a:FirstName>Rob</a:FirstName>
<a:Id i:nil="true"/>
<a:LastName>Bowman</a:LastName>
</a:Customer>
</GetServiceRequestDetailsResult>
I need to get the /ContractTransport/Value where the /ContractTransport/Name='Email'.
The following xpath gets me to ContactTransport /*[local-name()='GetServiceRequestDetailsResponse']/*[local-name()='GetServiceRequestDetailsResult']/*[local-name()='Customer']/*[local-name()='ContactTransports']/*[local-name()='ContactTransport']
If there were no namespaces then I guess I could suffix with [Name='Email]/*[local-name()='Value'] but this doesn't work now.
xml xpath xpath-1.0
add a comment |
There are lots of answers with no namespaces involved but I'm having trouble with the namespace.
Here's the xml doc:
<GetServiceRequestDetailsResponse xmlns="http://lcc.catscrm">
<GetServiceRequestDetailsResult xmlns:a="http://schemas.datacontract.org/2004/07/LCC.CATS.CRM.WCF.Model" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:AltRefs>
<a:AltRefModel>
<a:Name>UTRN</a:Name>
<a:TypeId>7577</a:TypeId>
<a:Value>9024930</a:Value>
</a:AltRefModel>
</a:AltRefs>
<a:Customer>
<a:Address>
<a:Address1>5</a:Address1>
<a:Address2>Random</a:Address2>
<a:County>West Yorks</a:County>
<a:NumberName>5</a:NumberName>
<a:Postcode>L1</a:Postcode>
<a:TownCity>London</a:TownCity>
<a:UPRN i:nil="true"/>
</a:Address>
<a:AltRefs/>
<a:ContactTransports>
<a:ContactTransport>
<a:Name>MobileNumber</a:Name>
<a:TypeId>3</a:TypeId>
<a:Value>08965</a:Value>
</a:ContactTransport>
<a:ContactTransport>
<a:Name>Email</a:Name>
<a:TypeId>1</a:TypeId>
<a:Value>a@b.com</a:Value>
</a:ContactTransport>
</a:ContactTransports>
<a:CustomerUPRN i:nil="true"/>
<a:FirstName>Rob</a:FirstName>
<a:Id i:nil="true"/>
<a:LastName>Bowman</a:LastName>
</a:Customer>
</GetServiceRequestDetailsResult>
I need to get the /ContractTransport/Value where the /ContractTransport/Name='Email'.
The following xpath gets me to ContactTransport /*[local-name()='GetServiceRequestDetailsResponse']/*[local-name()='GetServiceRequestDetailsResult']/*[local-name()='Customer']/*[local-name()='ContactTransports']/*[local-name()='ContactTransport']
If there were no namespaces then I guess I could suffix with [Name='Email]/*[local-name()='Value'] but this doesn't work now.
xml xpath xpath-1.0
add a comment |
There are lots of answers with no namespaces involved but I'm having trouble with the namespace.
Here's the xml doc:
<GetServiceRequestDetailsResponse xmlns="http://lcc.catscrm">
<GetServiceRequestDetailsResult xmlns:a="http://schemas.datacontract.org/2004/07/LCC.CATS.CRM.WCF.Model" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:AltRefs>
<a:AltRefModel>
<a:Name>UTRN</a:Name>
<a:TypeId>7577</a:TypeId>
<a:Value>9024930</a:Value>
</a:AltRefModel>
</a:AltRefs>
<a:Customer>
<a:Address>
<a:Address1>5</a:Address1>
<a:Address2>Random</a:Address2>
<a:County>West Yorks</a:County>
<a:NumberName>5</a:NumberName>
<a:Postcode>L1</a:Postcode>
<a:TownCity>London</a:TownCity>
<a:UPRN i:nil="true"/>
</a:Address>
<a:AltRefs/>
<a:ContactTransports>
<a:ContactTransport>
<a:Name>MobileNumber</a:Name>
<a:TypeId>3</a:TypeId>
<a:Value>08965</a:Value>
</a:ContactTransport>
<a:ContactTransport>
<a:Name>Email</a:Name>
<a:TypeId>1</a:TypeId>
<a:Value>a@b.com</a:Value>
</a:ContactTransport>
</a:ContactTransports>
<a:CustomerUPRN i:nil="true"/>
<a:FirstName>Rob</a:FirstName>
<a:Id i:nil="true"/>
<a:LastName>Bowman</a:LastName>
</a:Customer>
</GetServiceRequestDetailsResult>
I need to get the /ContractTransport/Value where the /ContractTransport/Name='Email'.
The following xpath gets me to ContactTransport /*[local-name()='GetServiceRequestDetailsResponse']/*[local-name()='GetServiceRequestDetailsResult']/*[local-name()='Customer']/*[local-name()='ContactTransports']/*[local-name()='ContactTransport']
If there were no namespaces then I guess I could suffix with [Name='Email]/*[local-name()='Value'] but this doesn't work now.
xml xpath xpath-1.0
There are lots of answers with no namespaces involved but I'm having trouble with the namespace.
Here's the xml doc:
<GetServiceRequestDetailsResponse xmlns="http://lcc.catscrm">
<GetServiceRequestDetailsResult xmlns:a="http://schemas.datacontract.org/2004/07/LCC.CATS.CRM.WCF.Model" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:AltRefs>
<a:AltRefModel>
<a:Name>UTRN</a:Name>
<a:TypeId>7577</a:TypeId>
<a:Value>9024930</a:Value>
</a:AltRefModel>
</a:AltRefs>
<a:Customer>
<a:Address>
<a:Address1>5</a:Address1>
<a:Address2>Random</a:Address2>
<a:County>West Yorks</a:County>
<a:NumberName>5</a:NumberName>
<a:Postcode>L1</a:Postcode>
<a:TownCity>London</a:TownCity>
<a:UPRN i:nil="true"/>
</a:Address>
<a:AltRefs/>
<a:ContactTransports>
<a:ContactTransport>
<a:Name>MobileNumber</a:Name>
<a:TypeId>3</a:TypeId>
<a:Value>08965</a:Value>
</a:ContactTransport>
<a:ContactTransport>
<a:Name>Email</a:Name>
<a:TypeId>1</a:TypeId>
<a:Value>a@b.com</a:Value>
</a:ContactTransport>
</a:ContactTransports>
<a:CustomerUPRN i:nil="true"/>
<a:FirstName>Rob</a:FirstName>
<a:Id i:nil="true"/>
<a:LastName>Bowman</a:LastName>
</a:Customer>
</GetServiceRequestDetailsResult>
I need to get the /ContractTransport/Value where the /ContractTransport/Name='Email'.
The following xpath gets me to ContactTransport /*[local-name()='GetServiceRequestDetailsResponse']/*[local-name()='GetServiceRequestDetailsResult']/*[local-name()='Customer']/*[local-name()='ContactTransports']/*[local-name()='ContactTransport']
If there were no namespaces then I guess I could suffix with [Name='Email]/*[local-name()='Value'] but this doesn't work now.
xml xpath xpath-1.0
xml xpath xpath-1.0
asked Nov 15 '18 at 11:22
Rob BowmanRob Bowman
2,7051558112
2,7051558112
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can add
/*[local-name()="Value" and preceding-sibling::*[local-name()="Name" and .="Email"]]
to your existed XPath to get required output
add a comment |
This might not be the most elegant option, but here's one:
//*[local-name()='ContactTransport']/*[local-name()='Value' and ../*[local-name()='Name' and text()='Email']]
This will select all Value
elements underneath a ContactTransport
that have a sibling whose Name
text is Email
. Demo.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318371%2fxpath-get-value-based-on-sibling-value-with-namespace%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can add
/*[local-name()="Value" and preceding-sibling::*[local-name()="Name" and .="Email"]]
to your existed XPath to get required output
add a comment |
You can add
/*[local-name()="Value" and preceding-sibling::*[local-name()="Name" and .="Email"]]
to your existed XPath to get required output
add a comment |
You can add
/*[local-name()="Value" and preceding-sibling::*[local-name()="Name" and .="Email"]]
to your existed XPath to get required output
You can add
/*[local-name()="Value" and preceding-sibling::*[local-name()="Name" and .="Email"]]
to your existed XPath to get required output
answered Nov 15 '18 at 12:08
AnderssonAndersson
39.1k113669
39.1k113669
add a comment |
add a comment |
This might not be the most elegant option, but here's one:
//*[local-name()='ContactTransport']/*[local-name()='Value' and ../*[local-name()='Name' and text()='Email']]
This will select all Value
elements underneath a ContactTransport
that have a sibling whose Name
text is Email
. Demo.
add a comment |
This might not be the most elegant option, but here's one:
//*[local-name()='ContactTransport']/*[local-name()='Value' and ../*[local-name()='Name' and text()='Email']]
This will select all Value
elements underneath a ContactTransport
that have a sibling whose Name
text is Email
. Demo.
add a comment |
This might not be the most elegant option, but here's one:
//*[local-name()='ContactTransport']/*[local-name()='Value' and ../*[local-name()='Name' and text()='Email']]
This will select all Value
elements underneath a ContactTransport
that have a sibling whose Name
text is Email
. Demo.
This might not be the most elegant option, but here's one:
//*[local-name()='ContactTransport']/*[local-name()='Value' and ../*[local-name()='Name' and text()='Email']]
This will select all Value
elements underneath a ContactTransport
that have a sibling whose Name
text is Email
. Demo.
answered Nov 15 '18 at 12:10
Robbie AverillRobbie Averill
21.2k74177
21.2k74177
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318371%2fxpath-get-value-based-on-sibling-value-with-namespace%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown