Help needed XML Field Extraction


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed XML Field Extraction
# 1  
Old 09-13-2010
Help needed XML Field Extraction

I had an immediate work to sort out the error code and error message which are associated within the log. But here im facing an problem to extract 3 different fields from the XML log can some one please help. I tried using different script including awk & nawk, but not getting the desired output.

Here is the Log

Code:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://integration.xyz.com/common/Errora.xsd">
    <SOAP-ENV:Body>
        <SOAP-ENV:Fault>
            <faultcode>Error.800</faultcode>
            <faultstring>Communicating error</faultstring>
            <faultactor>System12</faultactor>
            <detail>
                <ns1:errorDetailItem>
                    <ns1:providerError>
                        <ns1:providerErrorCode>Error.800</ns1:providerErrorCode>
                        <ns1:providerErrorText>Failed to establish a backside connection</ns1:providerErrorText>
                    </ns1:providerError>
                    <ns1:providerError>
                        <ns1:providerErrorCode>Error.800</ns1:providerErrorCode>
                        <ns1:providerErrorText>Communicating  error</ns1:providerErrorText>
                        <ns1:errorSystem>System12</ns1:errorSystem>
                    </ns1:providerError>
                </ns1:errorDetailItem>
            </detail>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I want only these fields front this log:

<ns1:providerErrorCode>Error.800</ns1:providerErrorCode>
<ns1:providerErrorText>Failed to establish a backside connection</ns1:providerErrorText>

Last edited by raghunsi; 09-13-2010 at 07:47 AM.. Reason: Adding noparse tabs last 2 lines
# 2  
Old 09-13-2010
Hi ,
Try this,
Code:
 perl -nle 'if (/<ns1:providerError(Code|Text)>(.+?)<\/ns1:providerError(Code|Text)>/) {print $_;}' inputfile

# 3  
Old 09-13-2010
Code:
grep -i "Error" ur_file

i think this wil do.. if what you looking out is all the lines with erorr in them,. But if u want something more specific. kindly let me know if you want only 1 line or more than 1 line...... (for Error.800). in the code pasted above by you .. there are more than 1 line which says Error.800
# 4  
Old 09-13-2010
When you remove the XML Tree, the complete piece of code is only a single line. I used CUT command to pull by the column wise(Each byte is one column) of the expression, but the output varies from one log to another some thing like this.
Code:
>Failed to establish a backside connection>Error.800</ns1:providerErrorCode><ns1:providerErrorText>Communication error
d to establish a backside connection</ns1:r.800</ns1:providerErrorCode><ns1:providerErrorText>Communication error</ns1:
ed to establish a backside connection</ns1er.800</ns1:providerErrorCode><ns1:providerErrorText>Communication error</ns1
d to establish a backside connection</ns1:r.800</ns1:providerErrorCode><ns1:providerErrorText>Communication error</ns1:
t>Failed to establish a backside connectioe>error.800</ns1:providerErrorCode><ns1:providerErrorText>Communication erro

I tested your perl script but still getting error

Code:
perl -nle 'if (/<ns1:providerError(Code|Text)>(.+?)<\/ns1:providerError(Code|Text)>/) {print $_;}'dealerlistservice_Log[1-5]_2010*.log.gz
Bareword found where operator expected at -e line 1, near "]_2010"
        (Missing operator before _2010?)
Warning: Use of "log" without parentheses is ambiguous at -e line 1.
syntax error at -e line 1, near "dealerlistservice_Log["
Execution of -e aborted due to compilation errors.


Last edited by Franklin52; 09-13-2010 at 06:53 AM.. Reason: Adding noparse tabs
# 5  
Old 09-13-2010
Code:
perl -nle 'if (/<ns1:providerError(Code|Text)>(.+?)<\/ns1:providerError(Code|Text)>/) {print $_;}' dealerlistservice_Log[1-5]_2010*.log.gz

Should be space between end of code and filename. and first unzip the file and try the code
# 6  
Old 09-13-2010
A slight modification based on Pravin solution:

Code:
perl -nle 'next unless /(providerError.*>)([^<]*)(<.*\1)/;print' inputfile

# 7  
Old 09-13-2010
Im not getting the write output from the above syntax. But im getting something using this, but not worth of it.

Code:
gzmore dealerlistservice_Log[1-5]_2010*.log.gz| grep -i Error* | nawk -RS'<ns1:providerErrorCode>^\*|</ns1:providerErrorCode>' '{print $NF}'

The output of this syntax is something like this

Quote:

ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
error</ns1SmilieroviderErrorText>
<ns1:errorSystem>SYSTEM12</ns1:errorSystem>
</ns1SmilieroviderError>
</ns1:errorDetailItem>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>





---------- Post updated at 02:43 AM ---------- Previous update was at 02:38 AM ----------

My Desired output must be just like this

Quote:
<ns1SmilieroviderErrorCode>Error.800</ns1SmilieroviderErrorCode>
<ns1SmilieroviderErrorText>Failed to establish a backside connection</ns1SmilieroviderErrorText>
<ns1SmilieroviderErrorText>Communication error</ns1SmilieroviderErrorText>
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with tag value extraction from xml file based on a matching condition

Hi , I have a situation where I need to search an xml file for the presence of a tag <FollowOnFrom> and also , presence of partial part of the following tag <ContractRequest _LoadId and if these 2 exist ,then extract the value from the following tag <_LocalId> which is "CW2094139". There... (2 Replies)
Discussion started by: paul1234
2 Replies

2. Shell Programming and Scripting

Help with XML tag value extraction based on condition

sample xml file part <?xml version="1.0" encoding="UTF-8"?><ContractWorkspace xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" _LoadId="export_AJ6iAFmh+pQHq1" xsi:noNamespaceSchemaLocation="ContractWorkspace.xsd"> <_LocalId>CW2218471</_LocalId> <Active>true</Active> ... (3 Replies)
Discussion started by: paul1234
3 Replies

3. Shell Programming and Scripting

Help with XML tag value extraction based on matching condition

sample xml file part <DocumentMinorVersion>0</DocumentMinorVersion> <DocumentVersion>1</DocumentVersion> <EffectiveDate>2017-05-30T00:00:00Z</EffectiveDate> <FollowOnFrom> <ContractRequest _LoadId="export_AJ6iAFoh6g0rE9"> <_LocalId>CRW2218451</_LocalId> ... (4 Replies)
Discussion started by: paul1234
4 Replies

4. Shell Programming and Scripting

Data extraction from .xml file

Hello, I'm attempting to extract 13 digit numbers beginning with 978 from a data file with the following command: awk '{ for(i=1;i<=NF;i++) if($i ~ /^978/) print $i; }' datafile > outfile This typically works. However, the new data file is an .xml file, and this command is no longer working... (6 Replies)
Discussion started by: palex
6 Replies

5. Shell Programming and Scripting

Regular Expression needed for the xml

I would like to match the regular below xml snippet by using the following grep command. I want match the lines as well could some please help me .. grep -il "<tokenValue>.*.</tokenValue>\n...*.amey.*.</userName>" ... (6 Replies)
Discussion started by: ameyrk
6 Replies

6. Red Hat

How to get a particular field from xml file?

i have a xml file and in that input file path is given. how to fetch that input file path using shell script. (4 Replies)
Discussion started by: ramsavi
4 Replies

7. Shell Programming and Scripting

XML parsing using nawk help needed

i need one help, below is one more xml file with diff pattern i tried it but dint get it , iam sure its a peice of cake for you guys. <xn:MeContext id="LSVLKY001"> <xn:ManagedElement id="1"> <un:RncFunction id="1"> <un:UtranCell... (2 Replies)
Discussion started by: tech_frk
2 Replies

8. Shell Programming and Scripting

How to get a field from an XML?

We have an input XML of the following form <item> <account>1234</account> <id>345</id> </item> How do we get the value of <account> tag (1234) using UNIX ? (6 Replies)
Discussion started by: Jassz
6 Replies

9. Shell Programming and Scripting

data extraction from xml file

I have an of xml file as shown below <?xml version='1.0' encoding='ASCII' standalone='yes' ?> <Station Index="10264" > <Number Value="237895890" /> <Position Lat="-29.5" Lon="3.5" /> <MaxDepth Value="-4939" /> <VeloLines Count="24"> <VeloLine Index="0" > <Depth... (3 Replies)
Discussion started by: shashi792
3 Replies

10. Shell Programming and Scripting

Problem in extraction when space is a field delimiter

I have more than 1000 files to parse. Each file contains few lines (number of lines varies) followed by a header line having all column's name (SPOT, NAME etc) and then values for those columns. **Example File: sdgafh dfhaadfha sfgaf dhah jkthdj SPOT NAME GENE_NAME CH_MEAN CHDN_MED ... (11 Replies)
Discussion started by: AshwaniSharma09
11 Replies
Login or Register to Ask a Question