Get the xml nodes where the search text is found
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I having a well formatted and Indented xml similar to the below one. I need to get the mono tags which has a text " http://yahoo.com "
<root>
<mono id="1">
<tag1>http://google.com</tag1>
</mono>
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono>
<mono id="3">
<tag1>http://mysite.com</tag1>
</mono>
<mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
</root>
I was trying with the below command.
cat -n index.xml | sed -n "/root/,/root>/p" | grep "http://yahoo.com"
6 <tag1>http://yahoo.com</tag1>
12 <tag1>http://yahoo.com</tag1>
I need output like this.But don't know how to get the mono nodes which has my search text.
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono>
<mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
Kindly help
shell-script files xml
add a comment |Â
up vote
0
down vote
favorite
I having a well formatted and Indented xml similar to the below one. I need to get the mono tags which has a text " http://yahoo.com "
<root>
<mono id="1">
<tag1>http://google.com</tag1>
</mono>
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono>
<mono id="3">
<tag1>http://mysite.com</tag1>
</mono>
<mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
</root>
I was trying with the below command.
cat -n index.xml | sed -n "/root/,/root>/p" | grep "http://yahoo.com"
6 <tag1>http://yahoo.com</tag1>
12 <tag1>http://yahoo.com</tag1>
I need output like this.But don't know how to get the mono nodes which has my search text.
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono>
<mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
Kindly help
shell-script files xml
I would recommend you to usexsltproc
fromlibxml2
toolkit to achieve your goal
â Serge
Jan 22 at 7:28
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I having a well formatted and Indented xml similar to the below one. I need to get the mono tags which has a text " http://yahoo.com "
<root>
<mono id="1">
<tag1>http://google.com</tag1>
</mono>
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono>
<mono id="3">
<tag1>http://mysite.com</tag1>
</mono>
<mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
</root>
I was trying with the below command.
cat -n index.xml | sed -n "/root/,/root>/p" | grep "http://yahoo.com"
6 <tag1>http://yahoo.com</tag1>
12 <tag1>http://yahoo.com</tag1>
I need output like this.But don't know how to get the mono nodes which has my search text.
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono>
<mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
Kindly help
shell-script files xml
I having a well formatted and Indented xml similar to the below one. I need to get the mono tags which has a text " http://yahoo.com "
<root>
<mono id="1">
<tag1>http://google.com</tag1>
</mono>
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono>
<mono id="3">
<tag1>http://mysite.com</tag1>
</mono>
<mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
</root>
I was trying with the below command.
cat -n index.xml | sed -n "/root/,/root>/p" | grep "http://yahoo.com"
6 <tag1>http://yahoo.com</tag1>
12 <tag1>http://yahoo.com</tag1>
I need output like this.But don't know how to get the mono nodes which has my search text.
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono>
<mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
Kindly help
shell-script files xml
asked Jan 22 at 6:35
Samuel Finny
154
154
I would recommend you to usexsltproc
fromlibxml2
toolkit to achieve your goal
â Serge
Jan 22 at 7:28
add a comment |Â
I would recommend you to usexsltproc
fromlibxml2
toolkit to achieve your goal
â Serge
Jan 22 at 7:28
I would recommend you to use
xsltproc
from libxml2
toolkit to achieve your goalâ Serge
Jan 22 at 7:28
I would recommend you to use
xsltproc
from libxml2
toolkit to achieve your goalâ Serge
Jan 22 at 7:28
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
Using XMLStarlet:
$ xml sel -t -c '//mono[tag1 = "http://yahoo.com"]' -nl file.xml
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono><mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
The XPath //mono[tag1 = "http://yahoo.com"]
means "any mongo
node that has a sub-node called tag1
whose value is http://yahoo.com
". The -c
means "give me a copy of ..." and the final -nl
inserts a newline at the end of the output.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Using XMLStarlet:
$ xml sel -t -c '//mono[tag1 = "http://yahoo.com"]' -nl file.xml
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono><mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
The XPath //mono[tag1 = "http://yahoo.com"]
means "any mongo
node that has a sub-node called tag1
whose value is http://yahoo.com
". The -c
means "give me a copy of ..." and the final -nl
inserts a newline at the end of the output.
add a comment |Â
up vote
0
down vote
Using XMLStarlet:
$ xml sel -t -c '//mono[tag1 = "http://yahoo.com"]' -nl file.xml
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono><mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
The XPath //mono[tag1 = "http://yahoo.com"]
means "any mongo
node that has a sub-node called tag1
whose value is http://yahoo.com
". The -c
means "give me a copy of ..." and the final -nl
inserts a newline at the end of the output.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Using XMLStarlet:
$ xml sel -t -c '//mono[tag1 = "http://yahoo.com"]' -nl file.xml
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono><mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
The XPath //mono[tag1 = "http://yahoo.com"]
means "any mongo
node that has a sub-node called tag1
whose value is http://yahoo.com
". The -c
means "give me a copy of ..." and the final -nl
inserts a newline at the end of the output.
Using XMLStarlet:
$ xml sel -t -c '//mono[tag1 = "http://yahoo.com"]' -nl file.xml
<mono id="2">
<tag1>http://yahoo.com</tag1>
</mono><mono id="4">
<tag1>http://yahoo.com</tag1>
</mono>
The XPath //mono[tag1 = "http://yahoo.com"]
means "any mongo
node that has a sub-node called tag1
whose value is http://yahoo.com
". The -c
means "give me a copy of ..." and the final -nl
inserts a newline at the end of the output.
answered Jan 22 at 8:03
Kusalananda
103k13202319
103k13202319
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418763%2fget-the-xml-nodes-where-the-search-text-is-found%23new-answer', 'question_page');
);
Post as a guest
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
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
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
I would recommend you to use
xsltproc
fromlibxml2
toolkit to achieve your goalâ Serge
Jan 22 at 7:28