The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-02-2008
naughty21 naughty21 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 16
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..
  #2 (permalink)  
Old 12-02-2008
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
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.
  #3 (permalink)  
Old 12-02-2008
summer_cherry summer_cherry is online now Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,098
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";
		$_=$';
	}
}

  #4 (permalink)  
Old 12-03-2008
naughty21 naughty21 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 16
Quote:
Originally Posted by summer_cherry View Post
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";
		$_=$';
	}
}
i need to find out the fieldvalue length means data length which is in between tags

Last edited by naughty21; 12-04-2008 at 02:04 PM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0