Find the value between two ranges in xml file of one particular tag

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have xml file where having tags <a>0000123</a>, <a>1200000</a>, <a>0001000</a>.



I need to get only the value which this particular tag should be between 100 to 1000.







share|improve this question






















  • tag will be in format of <a>0000123</a>
    – Ugan
    Feb 27 at 13:32










  • So the tags are a tags (all a tags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?
    – Kusalananda
    Feb 27 at 13:33







  • 1




    Please edit your question and add a xml example
    – ChristophS
    Feb 27 at 13:36














up vote
0
down vote

favorite












I have xml file where having tags <a>0000123</a>, <a>1200000</a>, <a>0001000</a>.



I need to get only the value which this particular tag should be between 100 to 1000.







share|improve this question






















  • tag will be in format of <a>0000123</a>
    – Ugan
    Feb 27 at 13:32










  • So the tags are a tags (all a tags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?
    – Kusalananda
    Feb 27 at 13:33







  • 1




    Please edit your question and add a xml example
    – ChristophS
    Feb 27 at 13:36












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have xml file where having tags <a>0000123</a>, <a>1200000</a>, <a>0001000</a>.



I need to get only the value which this particular tag should be between 100 to 1000.







share|improve this question














I have xml file where having tags <a>0000123</a>, <a>1200000</a>, <a>0001000</a>.



I need to get only the value which this particular tag should be between 100 to 1000.









share|improve this question













share|improve this question




share|improve this question








edited Feb 27 at 13:46









Kusalananda

103k13202318




103k13202318










asked Feb 27 at 13:32









Ugan

1




1











  • tag will be in format of <a>0000123</a>
    – Ugan
    Feb 27 at 13:32










  • So the tags are a tags (all a tags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?
    – Kusalananda
    Feb 27 at 13:33







  • 1




    Please edit your question and add a xml example
    – ChristophS
    Feb 27 at 13:36
















  • tag will be in format of <a>0000123</a>
    – Ugan
    Feb 27 at 13:32










  • So the tags are a tags (all a tags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?
    – Kusalananda
    Feb 27 at 13:33







  • 1




    Please edit your question and add a xml example
    – ChristophS
    Feb 27 at 13:36















tag will be in format of <a>0000123</a>
– Ugan
Feb 27 at 13:32




tag will be in format of <a>0000123</a>
– Ugan
Feb 27 at 13:32












So the tags are a tags (all a tags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?
– Kusalananda
Feb 27 at 13:33





So the tags are a tags (all a tags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?
– Kusalananda
Feb 27 at 13:33





1




1




Please edit your question and add a xml example
– ChristophS
Feb 27 at 13:36




Please edit your question and add a xml example
– ChristophS
Feb 27 at 13:36










2 Answers
2






active

oldest

votes

















up vote
1
down vote













Using XMLStarlet:



xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml


This will return a list of values between 100 and 1000. These values will be taken from the values of the a nodes of the XML document in file.xml, regardless of where these appear. Zero-filled numbers seems to be handled properly. The -nl at the end ensures that the output's last line has a newline at the end.



On some systems, XMLStarlet is installed as xmlstarlet instead of just xml.



Example:



$ cat file.xml
<?xml version="1.0"?>
<root>
<a>0000123</a>
<a>1200000</a>
<a>0001000</a>
</root>

$ xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
0000123





share|improve this answer






















  • In my case (kubuntu 17.10, bash) the command of the xmlstarlet package is xmlstarlet instead of xml. Works like a charme and does not look too complicated ;)
    – ChristophS
    Feb 27 at 15:09

















up vote
1
down vote













With xmllint :



xmllint --xpath '//a[text() > 100 and text() < 1000]/text()' file.xml


If you want to separate with newlines :



xmllint --shell file.xml <<< 'xpath //a[text() > 100 and text() < 000]/text()' |
grep -oP 'content=K.*'


AFAIK, it's a limitation of using xmllint without the switch --shell






share|improve this answer






















  • How do you separate the result? for example by nl or whitespace ...
    – ChristophS
    Feb 27 at 14:55










  • Check my edited post
    – Gilles Quenot
    Feb 27 at 15:01






  • 1




    As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/…). Great answer anyway!
    – ChristophS
    Feb 27 at 15:04










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426939%2ffind-the-value-between-two-ranges-in-xml-file-of-one-particular-tag%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Using XMLStarlet:



xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml


This will return a list of values between 100 and 1000. These values will be taken from the values of the a nodes of the XML document in file.xml, regardless of where these appear. Zero-filled numbers seems to be handled properly. The -nl at the end ensures that the output's last line has a newline at the end.



On some systems, XMLStarlet is installed as xmlstarlet instead of just xml.



Example:



$ cat file.xml
<?xml version="1.0"?>
<root>
<a>0000123</a>
<a>1200000</a>
<a>0001000</a>
</root>

$ xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
0000123





share|improve this answer






















  • In my case (kubuntu 17.10, bash) the command of the xmlstarlet package is xmlstarlet instead of xml. Works like a charme and does not look too complicated ;)
    – ChristophS
    Feb 27 at 15:09














up vote
1
down vote













Using XMLStarlet:



xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml


This will return a list of values between 100 and 1000. These values will be taken from the values of the a nodes of the XML document in file.xml, regardless of where these appear. Zero-filled numbers seems to be handled properly. The -nl at the end ensures that the output's last line has a newline at the end.



On some systems, XMLStarlet is installed as xmlstarlet instead of just xml.



Example:



$ cat file.xml
<?xml version="1.0"?>
<root>
<a>0000123</a>
<a>1200000</a>
<a>0001000</a>
</root>

$ xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
0000123





share|improve this answer






















  • In my case (kubuntu 17.10, bash) the command of the xmlstarlet package is xmlstarlet instead of xml. Works like a charme and does not look too complicated ;)
    – ChristophS
    Feb 27 at 15:09












up vote
1
down vote










up vote
1
down vote









Using XMLStarlet:



xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml


This will return a list of values between 100 and 1000. These values will be taken from the values of the a nodes of the XML document in file.xml, regardless of where these appear. Zero-filled numbers seems to be handled properly. The -nl at the end ensures that the output's last line has a newline at the end.



On some systems, XMLStarlet is installed as xmlstarlet instead of just xml.



Example:



$ cat file.xml
<?xml version="1.0"?>
<root>
<a>0000123</a>
<a>1200000</a>
<a>0001000</a>
</root>

$ xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
0000123





share|improve this answer














Using XMLStarlet:



xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml


This will return a list of values between 100 and 1000. These values will be taken from the values of the a nodes of the XML document in file.xml, regardless of where these appear. Zero-filled numbers seems to be handled properly. The -nl at the end ensures that the output's last line has a newline at the end.



On some systems, XMLStarlet is installed as xmlstarlet instead of just xml.



Example:



$ cat file.xml
<?xml version="1.0"?>
<root>
<a>0000123</a>
<a>1200000</a>
<a>0001000</a>
</root>

$ xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
0000123






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 27 at 13:51

























answered Feb 27 at 13:40









Kusalananda

103k13202318




103k13202318











  • In my case (kubuntu 17.10, bash) the command of the xmlstarlet package is xmlstarlet instead of xml. Works like a charme and does not look too complicated ;)
    – ChristophS
    Feb 27 at 15:09
















  • In my case (kubuntu 17.10, bash) the command of the xmlstarlet package is xmlstarlet instead of xml. Works like a charme and does not look too complicated ;)
    – ChristophS
    Feb 27 at 15:09















In my case (kubuntu 17.10, bash) the command of the xmlstarlet package is xmlstarlet instead of xml. Works like a charme and does not look too complicated ;)
– ChristophS
Feb 27 at 15:09




In my case (kubuntu 17.10, bash) the command of the xmlstarlet package is xmlstarlet instead of xml. Works like a charme and does not look too complicated ;)
– ChristophS
Feb 27 at 15:09












up vote
1
down vote













With xmllint :



xmllint --xpath '//a[text() > 100 and text() < 1000]/text()' file.xml


If you want to separate with newlines :



xmllint --shell file.xml <<< 'xpath //a[text() > 100 and text() < 000]/text()' |
grep -oP 'content=K.*'


AFAIK, it's a limitation of using xmllint without the switch --shell






share|improve this answer






















  • How do you separate the result? for example by nl or whitespace ...
    – ChristophS
    Feb 27 at 14:55










  • Check my edited post
    – Gilles Quenot
    Feb 27 at 15:01






  • 1




    As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/…). Great answer anyway!
    – ChristophS
    Feb 27 at 15:04














up vote
1
down vote













With xmllint :



xmllint --xpath '//a[text() > 100 and text() < 1000]/text()' file.xml


If you want to separate with newlines :



xmllint --shell file.xml <<< 'xpath //a[text() > 100 and text() < 000]/text()' |
grep -oP 'content=K.*'


AFAIK, it's a limitation of using xmllint without the switch --shell






share|improve this answer






















  • How do you separate the result? for example by nl or whitespace ...
    – ChristophS
    Feb 27 at 14:55










  • Check my edited post
    – Gilles Quenot
    Feb 27 at 15:01






  • 1




    As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/…). Great answer anyway!
    – ChristophS
    Feb 27 at 15:04












up vote
1
down vote










up vote
1
down vote









With xmllint :



xmllint --xpath '//a[text() > 100 and text() < 1000]/text()' file.xml


If you want to separate with newlines :



xmllint --shell file.xml <<< 'xpath //a[text() > 100 and text() < 000]/text()' |
grep -oP 'content=K.*'


AFAIK, it's a limitation of using xmllint without the switch --shell






share|improve this answer














With xmllint :



xmllint --xpath '//a[text() > 100 and text() < 1000]/text()' file.xml


If you want to separate with newlines :



xmllint --shell file.xml <<< 'xpath //a[text() > 100 and text() < 000]/text()' |
grep -oP 'content=K.*'


AFAIK, it's a limitation of using xmllint without the switch --shell







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 27 at 15:01

























answered Feb 27 at 14:36









Gilles Quenot

15.3k13448




15.3k13448











  • How do you separate the result? for example by nl or whitespace ...
    – ChristophS
    Feb 27 at 14:55










  • Check my edited post
    – Gilles Quenot
    Feb 27 at 15:01






  • 1




    As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/…). Great answer anyway!
    – ChristophS
    Feb 27 at 15:04
















  • How do you separate the result? for example by nl or whitespace ...
    – ChristophS
    Feb 27 at 14:55










  • Check my edited post
    – Gilles Quenot
    Feb 27 at 15:01






  • 1




    As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/…). Great answer anyway!
    – ChristophS
    Feb 27 at 15:04















How do you separate the result? for example by nl or whitespace ...
– ChristophS
Feb 27 at 14:55




How do you separate the result? for example by nl or whitespace ...
– ChristophS
Feb 27 at 14:55












Check my edited post
– Gilles Quenot
Feb 27 at 15:01




Check my edited post
– Gilles Quenot
Feb 27 at 15:01




1




1




As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/…). Great answer anyway!
– ChristophS
Feb 27 at 15:04




As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/…). Great answer anyway!
– ChristophS
Feb 27 at 15:04












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426939%2ffind-the-value-between-two-ranges-in-xml-file-of-one-particular-tag%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)