XML parsing with awk - getXML.awk
flag
Messages 21 - 27 of 27 - Collapse all
/groups/adfetch?adid=CqEV9BEAAAB0qJNGgj6U7vIcWD9L128uFSRgCP-avRN4YT0eROC0jw
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
21.  Jan Weber  
View profile  
 More options Jul 19 2005, 5:08 am
Newsgroups: comp.lang.awk
From: "Jan Weber" <ja...@web.de>
Date: Tue, 19 Jul 2005 11:08:57 +0200
Local: Tues, Jul 19 2005 5:08 am
Subject: Re: XML parsing with awk - getXML.awk

I'm also thinking about a function putXML(), but i am not sure with the interface.
It should either operate on the XTYPE,XITEM,XATTR triple for streaming processing or
on XNODE for the DOM style part.
And it should be as simple as possible.

I thought about something like this:

function putXML( file, xtype_or_xnode, xitem, xattr ) {
   code determines whether xtype_or_xnode is xtype or xnode
   and uses xtype,xitem,xattr or xnode respectively.

}

or (currently my favorite):

function putXML( file, xnode ) {
   code uses xnode, except if xnode is empty (not set) then it uses
   global vars XTYPE,XITEM,XATTR

}

or even

function putXML( file, flagUseXNODE ) {
   if flagUseXNODE is set, code uses global var XNODE
   else it uses global vars XTYPE,XITEM,XATTR

}

with the last two versions it would be possible to write code like this:

# Example: increment the attribute named "bar" in all elements named "foo"
BEGIN {
     while ( getXML(ARGV[1]) ) {
         if (XTYPE=="TAG" && XITEM=="foo") {
             XATTR["bar"]++;
             putXML(ARGV[2]);
         }
     }

}

And this would finally be "XML processing with AWK" instead of just parsing ;-)
Comments are welcome.

Regards,
Jan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
22.  Jan Weber  
View profile  
 More options Jul 19 2005, 5:20 am
Newsgroups: comp.lang.awk
From: "Jan Weber" <ja...@web.de>
Date: Tue, 19 Jul 2005 11:20:36 +0200
Local: Tues, Jul 19 2005 5:20 am
Subject: Re: XML parsing with awk - getXML.awk

Example corrected:

# Example: increment the attribute named "bar" in all elements named "foo"
BEGIN {
      while ( getXML(ARGV[1]) ) {
          if (XTYPE=="TAG" && XITEM=="foo") XATTR["bar"]++;
          putXML(ARGV[2]);
      }


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
23.  Jürgen Kahrs  
View profile  
 More options Jul 23 2005, 2:48 pm
Newsgroups: comp.lang.awk
From: Jürgen Kahrs <Juergen.Kahrs_DELETET...@vr-web.de>
Date: Sat, 23 Jul 2005 20:48:31 +0200
Local: Sat, Jul 23 2005 2:48 pm
Subject: Re: XML parsing with awk - getXML.awk

Jan Weber wrote:
> I'm also thinking about a function putXML(), but i am not sure with the
> interface.

Good idea. Last year, Manuel Collado and Stefan Tramm
told me that there is an interesting Perl solution for
this problem.

> And this would finally be "XML processing with AWK" instead of just
> parsing ;-)

Indeed. Keep us posted about your advances.
And be prepared to write a chapter about it
in our manual.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
24.  Jan Weber  
View profile  
 More options Jul 24 2005, 10:58 am
Newsgroups: comp.lang.awk
From: "Jan Weber" <ja...@web.de>
Date: Sun, 24 Jul 2005 16:58:59 +0200
Local: Sun, Jul 24 2005 10:58 am
Subject: Re: XML parsing with awk - getXML.awk

On Sat, 23 Jul 2005 20:48:31 +0200, Jürgen Kahrs <Juergen.Kahrs_DELETET...@vr-web.de> wrote:
> Jan Weber wrote:

>> I'm also thinking about a function putXML(), but i am not sure with the
>> interface.

> Good idea. Last year, Manuel Collado and Stefan Tramm
> told me that there is an interesting Perl solution for
> this problem.

Can you give more information about the "interesting" part of this
solution, maybe a link or a short explanation?

>> And this would finally be "XML processing with AWK" instead of just
>> parsing ;-)

> Indeed. Keep us posted about your advances.

I will do, but maybe it will take a while, as I currently have
no need for such script.

> And be prepared to write a chapter about it
> in our manual.

I think about it.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
25.  Jürgen Kahrs  
View profile  
 More options Jul 24 2005, 4:10 pm
Newsgroups: comp.lang.awk
From: Jürgen Kahrs <Juergen.Kahrs_DELETET...@vr-web.de>
Date: Sun, 24 Jul 2005 22:10:37 +0200
Local: Sun, Jul 24 2005 4:10 pm
Subject: Re: XML parsing with awk - getXML.awk

Jan Weber wrote:
>> Good idea. Last year, Manuel Collado and Stefan Tramm
>> told me that there is an interesting Perl solution for
>> this problem.

> Can you give more information about the "interesting" part of this
> solution, maybe a link or a short explanation?

The interesting part of it was some functions
for assembling the textual output. For example
one function surrounded the text to be printed
with markup tags and attributes. I'm sorry thet
I cant remember the name of the Perl module.
Maybe someone else (Manuel, Stefan, Andrew) can
help with details ?

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
26.  Manuel Collado  
View profile  
 More options Jul 26 2005, 6:27 am
Newsgroups: comp.lang.awk
From: Manuel Collado <m.coll...@lml.ls.fi.upm.es>
Date: Tue, 26 Jul 2005 12:27:37 +0200
Local: Tues, Jul 26 2005 6:27 am
Subject: Re: XML parsing with awk - getXML.awk
Jürgen Kahrs escribió:

Here is the code I wrote for this purpose:

-----X---------------------------
# Extra functions for xmllib
#
# Author: Manuel Collado
# Date: June 2004

# generate the string for a XML attribute, with a leading space:
#     ' name="value"'
function attr( name, value ) {
     return " " name "=\"" value "\""

}

# generate the string for starting element tags
#  - several ">" delimited tags may be specified
#  - every tag can include attributes
# example:   'one att="val">two>three'
# generates:  '<one att="val"><two><three>'
function xse( tags,       n, t, k, s ) {
     n = split( tags, t, ">" )
     s = ""
     for (k=1; k<=n; k++) {
         s = s "<" t[k] ">"
     }
     return s

}

# generate the string for ending element tags, like xse, but
#  - in reverse order
#  - trimm attributes
function xee( tags,       n, t, k, s ) {
#print "---" tags
     n = split( tags, t, ">" )
     s = ""
     for (k=n; k>=1; k--) {
#print k "--" t[k]
         if (index(t[k], " ")) {
             s = s "</" substr(t[k], 1, index(t[k], " ")-1) ">"
         } else {
             s = s "</" t[k] ">"
         }
     }
     return s

}

# generate the string for a full xml element, combine xse and xee
function xml( tags, content ) {
     return xse(tags) content xee(tags)

}

# generate the string for a processing instruction
function xpi( pi ) {
     return "<?" pi "?>"

}

# generate the string for a simple DOCTYPE declaration
function doctype( root, public, url ) {
     if (public) {
         return "<!DOCTYPE " root " PUBLIC " public " " url " >"
     } else {
         return "<!DOCTYPE " root " SYSTEM "  url " >"
     }

}

# generate the string for a stylesheet processing instruction
# (type = css/xsl)
function xss( type, url ) {
     return xpi( "xsl-stylesheet" attr("type", "text/" type)
attr("href", url) )

}

# generate the string for a XML comment
function xcomment( comment ) {
     return "<!-- " comment " -->"
}

-----X---------------------------

Regards,
--
To reply by e-mail, please remove the extra dot
in the given address:  m.collado -> mcollado


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
27.  Jan Weber  
View profile  
 More options Jul 26 2005, 6:52 pm
Newsgroups: comp.lang.awk
From: "Jan Weber" <ja...@web.de>
Date: Wed, 27 Jul 2005 00:52:04 +0200
Local: Tues, Jul 26 2005 6:52 pm
Subject: Re: XML parsing with awk - getXML.awk

Thanks!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google