LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   extract node value from soap response (https://www.linuxquestions.org/questions/linux-newbie-8/extract-node-value-from-soap-response-4175562254/)

SuKHI 12-24-2015 02:15 AM

extract node value from soap response
 
Hi,

I have one soap xml response and it contains repeating node name.

sample as below:

Code:

<ax279:nodes xsi:type="ax277:ChildIdentifierList">
              <ax277:id>3</ax277:id>
              <ax277:name>test</ax277:name>
              <ax277:children xsi:type="ax277:EntityIdentifier">
                  <ax277:id>9</ax277:id>
                  </ax277:children>
              <ax277:children xsi:type="ax277:EntityIdentifier">
                  <ax277:id>10</ax277:id>
                  <ax277:name>hello.world</ax277:name>
              </ax277:children>
            </ax279:nodes>

I need to extract <ax277:name>test</ax277:name> value based on app name hello.world from xml.

But issue is hello.world keep repeating under other tags too.
And tag name <ax277:name> also repeating.
If it was only one then I would have done with awk or grep or sed.

But still there is problem:
I used grep as below:
Code:

grep -oPm1 "(?<=<ax277:name>)[^<]+" node.xml
its only returning me first occurred value under that tag.

Then i tried with awk, it has returned all the values w.r.t that tag.
Code:

awk -F "[><]" '/ax277:name/{print $3}' node.xml
Can I pass both parent tag name with child tag to get single value?

something like: awk -F "[><]" '/ax279:nodes/ax277:name/{print $3}' node.xml

i tried above but again its syntax error.

Any idea?

berndbausch 12-24-2015 09:48 AM

To be honest, I don't understand what you want to achieve. If you want to extract a line named <ax277:name>test</ax277:name>, why don't you grep for it? Or what is it exactly you want to extract? What does hello.world have to do with it?

Regarding the syntax error: You use this string as a pattern -
Code:

/ax279:nodes/ax277:name/
You can't have a pattern with three slashes, except if you quote the middle one. Therefore, syntax error.


All times are GMT -5. The time now is 09:51 PM.