XPath expression to pluck out attribute value
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have the following XML:
<envelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="vendor">
<fizz buzz="3"/>
</payload>
</envelope>
I am trying to write an XPath expression that will pluck out vendor
(value for the payload
's class
attribute) or whatever its value is.
My best attempts are:
/dataEnvelope/payload[@class="vendor"]@class
But this requires the expression to already know that vendor
is the value of the attribute. But if the XML is:
<dataEnvelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="foobar">
<fizz buzz="3"/>
</payload>
</dataEnvelope>
Then I want the expression to pluck out the foobar
. Any ideas where I'm going awry?
xpath
add a comment |
I have the following XML:
<envelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="vendor">
<fizz buzz="3"/>
</payload>
</envelope>
I am trying to write an XPath expression that will pluck out vendor
(value for the payload
's class
attribute) or whatever its value is.
My best attempts are:
/dataEnvelope/payload[@class="vendor"]@class
But this requires the expression to already know that vendor
is the value of the attribute. But if the XML is:
<dataEnvelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="foobar">
<fizz buzz="3"/>
</payload>
</dataEnvelope>
Then I want the expression to pluck out the foobar
. Any ideas where I'm going awry?
xpath
1
Which data you know initially? What you can use to identify required element?action
value,auditId
,... ?
– Andersson
Nov 16 '18 at 19:31
Is the difference between the two XML examples intentional? If so, state that you need to be able to handle that difference when selecting the@vendor
value. You can accommodate the difference in the XPath, if necessary. Otherwise, it would be less confusing for those answering if you didn't have<envelope>
and<dataEnvelope>
different.
– Mads Hansen
Nov 17 '18 at 2:57
add a comment |
I have the following XML:
<envelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="vendor">
<fizz buzz="3"/>
</payload>
</envelope>
I am trying to write an XPath expression that will pluck out vendor
(value for the payload
's class
attribute) or whatever its value is.
My best attempts are:
/dataEnvelope/payload[@class="vendor"]@class
But this requires the expression to already know that vendor
is the value of the attribute. But if the XML is:
<dataEnvelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="foobar">
<fizz buzz="3"/>
</payload>
</dataEnvelope>
Then I want the expression to pluck out the foobar
. Any ideas where I'm going awry?
xpath
I have the following XML:
<envelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="vendor">
<fizz buzz="3"/>
</payload>
</envelope>
I am trying to write an XPath expression that will pluck out vendor
(value for the payload
's class
attribute) or whatever its value is.
My best attempts are:
/dataEnvelope/payload[@class="vendor"]@class
But this requires the expression to already know that vendor
is the value of the attribute. But if the XML is:
<dataEnvelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="foobar">
<fizz buzz="3"/>
</payload>
</dataEnvelope>
Then I want the expression to pluck out the foobar
. Any ideas where I'm going awry?
xpath
xpath
asked Nov 16 '18 at 19:25
hotmeatballsouphotmeatballsoup
204314
204314
1
Which data you know initially? What you can use to identify required element?action
value,auditId
,... ?
– Andersson
Nov 16 '18 at 19:31
Is the difference between the two XML examples intentional? If so, state that you need to be able to handle that difference when selecting the@vendor
value. You can accommodate the difference in the XPath, if necessary. Otherwise, it would be less confusing for those answering if you didn't have<envelope>
and<dataEnvelope>
different.
– Mads Hansen
Nov 17 '18 at 2:57
add a comment |
1
Which data you know initially? What you can use to identify required element?action
value,auditId
,... ?
– Andersson
Nov 16 '18 at 19:31
Is the difference between the two XML examples intentional? If so, state that you need to be able to handle that difference when selecting the@vendor
value. You can accommodate the difference in the XPath, if necessary. Otherwise, it would be less confusing for those answering if you didn't have<envelope>
and<dataEnvelope>
different.
– Mads Hansen
Nov 17 '18 at 2:57
1
1
Which data you know initially? What you can use to identify required element?
action
value, auditId
,... ?– Andersson
Nov 16 '18 at 19:31
Which data you know initially? What you can use to identify required element?
action
value, auditId
,... ?– Andersson
Nov 16 '18 at 19:31
Is the difference between the two XML examples intentional? If so, state that you need to be able to handle that difference when selecting the
@vendor
value. You can accommodate the difference in the XPath, if necessary. Otherwise, it would be less confusing for those answering if you didn't have <envelope>
and <dataEnvelope>
different.– Mads Hansen
Nov 17 '18 at 2:57
Is the difference between the two XML examples intentional? If so, state that you need to be able to handle that difference when selecting the
@vendor
value. You can accommodate the difference in the XPath, if necessary. Otherwise, it would be less confusing for those answering if you didn't have <envelope>
and <dataEnvelope>
different.– Mads Hansen
Nov 17 '18 at 2:57
add a comment |
3 Answers
3
active
oldest
votes
If you need @class
value from payload
node, you can use
/dataEnvelope/payload[@class]/@class
or just
/dataEnvelope/payload/@class
add a comment |
At first, your two XML files are out-of-sync - one references envelope
and the other references dataEnvelope
. So exchange one for the other, if necessary.
So, to get the attribute value of payload
, you can use an XPath expression like this which uses a child's attribute value to be more specific:
/envelope/payload[fizz[@buzz='3']]/@class
Output is:
vendor
add a comment |
If the document element can/will change, then you can keep the XPath more generic and select the value of the class
attribute from the payload
element that is a child of any element:
/*/payload/@class
If you know that it will always be a child of envelope
, then this would be more specific(but the above would still work):
/envelope/payload/@class
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%2f53344182%2fxpath-expression-to-pluck-out-attribute-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you need @class
value from payload
node, you can use
/dataEnvelope/payload[@class]/@class
or just
/dataEnvelope/payload/@class
add a comment |
If you need @class
value from payload
node, you can use
/dataEnvelope/payload[@class]/@class
or just
/dataEnvelope/payload/@class
add a comment |
If you need @class
value from payload
node, you can use
/dataEnvelope/payload[@class]/@class
or just
/dataEnvelope/payload/@class
If you need @class
value from payload
node, you can use
/dataEnvelope/payload[@class]/@class
or just
/dataEnvelope/payload/@class
answered Nov 16 '18 at 19:29
AnderssonAndersson
39.2k113669
39.2k113669
add a comment |
add a comment |
At first, your two XML files are out-of-sync - one references envelope
and the other references dataEnvelope
. So exchange one for the other, if necessary.
So, to get the attribute value of payload
, you can use an XPath expression like this which uses a child's attribute value to be more specific:
/envelope/payload[fizz[@buzz='3']]/@class
Output is:
vendor
add a comment |
At first, your two XML files are out-of-sync - one references envelope
and the other references dataEnvelope
. So exchange one for the other, if necessary.
So, to get the attribute value of payload
, you can use an XPath expression like this which uses a child's attribute value to be more specific:
/envelope/payload[fizz[@buzz='3']]/@class
Output is:
vendor
add a comment |
At first, your two XML files are out-of-sync - one references envelope
and the other references dataEnvelope
. So exchange one for the other, if necessary.
So, to get the attribute value of payload
, you can use an XPath expression like this which uses a child's attribute value to be more specific:
/envelope/payload[fizz[@buzz='3']]/@class
Output is:
vendor
At first, your two XML files are out-of-sync - one references envelope
and the other references dataEnvelope
. So exchange one for the other, if necessary.
So, to get the attribute value of payload
, you can use an XPath expression like this which uses a child's attribute value to be more specific:
/envelope/payload[fizz[@buzz='3']]/@class
Output is:
vendor
answered Nov 16 '18 at 19:30
zx485zx485
15.4k133248
15.4k133248
add a comment |
add a comment |
If the document element can/will change, then you can keep the XPath more generic and select the value of the class
attribute from the payload
element that is a child of any element:
/*/payload/@class
If you know that it will always be a child of envelope
, then this would be more specific(but the above would still work):
/envelope/payload/@class
add a comment |
If the document element can/will change, then you can keep the XPath more generic and select the value of the class
attribute from the payload
element that is a child of any element:
/*/payload/@class
If you know that it will always be a child of envelope
, then this would be more specific(but the above would still work):
/envelope/payload/@class
add a comment |
If the document element can/will change, then you can keep the XPath more generic and select the value of the class
attribute from the payload
element that is a child of any element:
/*/payload/@class
If you know that it will always be a child of envelope
, then this would be more specific(but the above would still work):
/envelope/payload/@class
If the document element can/will change, then you can keep the XPath more generic and select the value of the class
attribute from the payload
element that is a child of any element:
/*/payload/@class
If you know that it will always be a child of envelope
, then this would be more specific(but the above would still work):
/envelope/payload/@class
answered Nov 17 '18 at 3:00
Mads HansenMads Hansen
45.1k1195123
45.1k1195123
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%2f53344182%2fxpath-expression-to-pluck-out-attribute-value%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
1
Which data you know initially? What you can use to identify required element?
action
value,auditId
,... ?– Andersson
Nov 16 '18 at 19:31
Is the difference between the two XML examples intentional? If so, state that you need to be able to handle that difference when selecting the
@vendor
value. You can accommodate the difference in the XPath, if necessary. Otherwise, it would be less confusing for those answering if you didn't have<envelope>
and<dataEnvelope>
different.– Mads Hansen
Nov 17 '18 at 2:57