format xml


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting format xml
# 1  
Old 03-23-2009
format xml

i want to grep to a file the

numerator-denominator, 1.23456, 1.78901

from the following xml tags.

Code:
<locks:pair xc:value="numerator/denominator" xc:type="Fields">
<mp:formFactor>1</mp:formFactor>
<mp:quotation>numerator-denominator</mp:quotation>
<mp:one>1.23456</mp:one>
<mp:two>1.78901</mp:tw0>
</locks:pair>

Mind you this only a snipet, I need this code to repeat muliple times within a file, as the snippet repeat itself with differnt variables.

thanks

Last edited by Franklin52; 03-23-2009 at 03:11 PM.. Reason: adding code tags
# 2  
Old 03-23-2009
if you are ready to write a perl script, CPAN modules XML::Parser or XML::Simple would be helpful
# 3  
Old 03-23-2009
I had seen where installing CPAN modules using the xml parser...
is there an alternative way without the modules?
# 4  
Old 03-25-2009
seems awk can help you some

Code:
nawk 'BEGIN{FS="[<:>]"}
{
	if( $3 ~ /(quotation|one|two)/)
		printf $4","
}' filename

# 5  
Old 03-25-2009
resolved

thanks for everyone response, but the following sed one liner did the job

sed -e :a -e 's/<[^>]*>//g;/</N;//ba'
# 6  
Old 03-25-2009
If you want an XSLT solution, the following stylesheet outputs the required elements.
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:locks="http://www.dummy.com/LOCKS"
     xmlns:xc="http://www.dummy.com/XC" 
     xmlns:mp="http://www.dummy.com/MP">

<xsl:output method="text"/>
<xsl:template match="locks:pair">
      <xsl:value-of select="@xc:value"/>, <xsl:value-of select="mp:one"/>, <xsl:value-of select="mp:two"/>
</xsl:template>

</xsl:stylesheet>

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert tag based lines to xml format

Hi All, Can some one help me to convert this line of code to xml format. Thanks in advance, preethy. input: ... (2 Replies)
Discussion started by: preethy
2 Replies

2. Shell Programming and Scripting

How can I replace data in between xml tags to required format?

Hi All, I have a requirement to change the data in xml file to required format. Below is the scenario. Please find the attached Xml file which contains data that I need to convert.. <ReleaseIndicatorList><ReleaseIndicator>Alternative... (0 Replies)
Discussion started by: Prathyu
0 Replies

3. Shell Programming and Scripting

From sql Insert Query to XML format

Hi How do I translate Let say Cat inserts.sql gives Insert into PM9_TAXATION_ROUNDING (STATE_GECODE, TAX_TYPE, TAX_AUTHORITY, SYS_CREATION_DATE, SYS_UPDATE_DATE, APPLICATION_ID, DL_SERVICE_CODE, ROUNDING_METHOD) Values ('xx', 'xx', 'x', TO_DATE('10/26/2012 13:01:20',... (3 Replies)
Discussion started by: anuj87in
3 Replies

4. Shell Programming and Scripting

XML dateTime format in shell script

How can i frame current date & time in the xml standard dateTime format in shell script 2011-10-18T12:00:00.000000 I got up to the date format using the below code date '+%Y'-'%m'-'%d'T ---------- Post updated at 09:10 AM ---------- Previous update was at 08:53 AM ---------- ... (6 Replies)
Discussion started by: vel4ever
6 Replies

5. Shell Programming and Scripting

Need to split a xml file in proper format

Hi, I have a file which has xml data but all in single line Ex - <?xml version="1.0"?><User><Name>Robert</Name><Location>California</Location><Occupation>Programmer</Occupation></User> I want to split the data in proper xml format Ex- <?xml version="1.0"?> <User> <Name>Robert</Name>... (6 Replies)
Discussion started by: avishek007
6 Replies

6. UNIX for Dummies Questions & Answers

XML / XSD: what is a good format for amounts?

Suppose I have a XSD definition of amount: <xs:element name="Amount" type="amount> And the amounts themselves are given in the following format in the XML: <amount>1.000.00</amount> In other words, the thousand separator and the decimal point are the same. Does this require that the parser... (3 Replies)
Discussion started by: figaro
3 Replies

7. Shell Programming and Scripting

XML format

Please help to convert the file which is tab separated into xml format 'Date' 'ID' 'Name' 'Time' 'Average Time' 2010-06-02 3 30943 00:00:50 1.39 2010-06-02 1 4545 00:01:03 2010-06-02 9 8203 00:01:00 (4 Replies)
Discussion started by: sandy1028
4 Replies

8. Shell Programming and Scripting

how to parse the file in xml format using awk/nawk

Hi All, I have an xml file with the below format. <a>111</a><b>222</b><c>333<c><d><e>123</e><f>234</f><d><e>456</e><f>789</f> output needed is 111,222,333,123,234 111,222,333,456,789 nawk 'BEGIN{FS="<|>"} {print a,b,c,e,f a="" ... (7 Replies)
Discussion started by: natalie23
7 Replies

9. Shell Programming and Scripting

Convert XML to CSV format

Can any one give the idea on this, please. I have the following XML file and wants to convert into CSV(comma separated value) format. <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE Waveset PUBLIC 'waveset.dtd' 'waveset.dtd'> <Waveset> <Object name='ra8736'> <Attribute name='ADDRESS'... (2 Replies)
Discussion started by: kumar04
2 Replies
Login or Register to Ask a Question