![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What the command to find out the record length of a fixed length file? | tranq01 | UNIX for Dummies Questions & Answers | 9 | 12-04-2008 04:04 PM |
| find the length of file names in a directory? | koti_rama | Shell Programming and Scripting | 5 | 06-04-2008 11:19 AM |
| Help with finding length of a field | dsravan | Shell Programming and Scripting | 6 | 12-13-2007 05:16 PM |
| Need find a file based length | J_ang | UNIX for Dummies Questions & Answers | 8 | 03-26-2007 09:21 AM |
| Validating fixed length field... | giannicello | UNIX for Dummies Questions & Answers | 12 | 05-22-2003 12:19 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How To Find Length of a Field in XML File
Hi
I have a xml file with below data...have to find the length of the filedvalues... <?xml version="1.0" encoding="ISO-8859-15" standalone="no"?><abc xmlns:xsi="http://www.w3.org/2000/XMLSchem a-instance"><FileHeader><FileName>VertSvcsDSL20081202103929.XML</FileName><NumOrderRecs>27</NumOrderRecs><NumDetailRecs>46</NumDetailRecs></FileHeader><OrderHeaderList><Order><CRMOrderID>0</CRMOrderID><CRMSvcOrderID>0</CRMSvcOrderID><UDCRMSONum>0</UDCRMSONum> filename , NumOrderRecs and NumDetailRecs ... are field names so need length of the data in between tags for ex: length of VertSvcsDSL20081202103929.XML any help in this Last edited by naughty21; 12-04-2008 at 02:04 PM.. |
|
||||
|
OK - can only give you a general type reply - this will require AWK.
Make your RS=">", that will break the input into lines containing the different fields. Then you would check to see if it is a start tag or or end tag field indicator by the last character being a "/" - When you fine a start-tag, the next record is your input value for that tag - unless it is an end-tag. Some of the things to be carefull for in XML It could be unicode based - what will you do then - awk and most UNIX utilities are bad at handling binary zeroes. I have seen XML files where it is a 25000 character single line. Perfectly leagal to XML, bad for vi on UNIX. That is the reason for the Field Separator definition to awk. in you example - filename looks like it contains two elements, and not other data. |
|
||||
|
hi, not very sure what's your defination for field. And also you are expecting length of filedname or fieldvalue. Anyway, below may help you a little. input: Code:
<FileName>VertSvcsDSL20081202103929.XML</FileName><NumOrderRecs>27</NumOrderRecs><NumDetailRecs>46</NumDetailRecs> output: Code:
FileName -- VertSvcsDSL20081202103929.XML -- FileName NumOrderRecs -- 27 -- NumOrderRecs NumDetailRecs -- 46 -- NumDetailRecs code: Code:
open FH,"<b.txt";
my @arr=<FH>;
close FH;
foreach(@arr){
while(m/<(.*?)>(.*?)<\/\1>/){
print $1," -- ",$2," -- ",$1,"\n";
$_=$';
}
}
|
|
||||
|
Quote:
Last edited by naughty21; 12-04-2008 at 02:04 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|