Parsing xml file

hi guys, great help to the original question, can i expand please?

i have large files filled with blocks like this

<Placemark>
network type: hot
line1
line2
line3
<styleUrl>red.png</styleUrl>
</Placemark>
<Placemark>
network type: cold
line1
line2
line3
<styleUrl>red.png</styleUrl>
</Placemark>
<Placemark>
network type: medium
line1
line2
line3
<styleUrl>red.png</styleUrl>
</Placemark>

..currently all styleUrl values are red.png, however i want to change this according to whatever value "network type:" is, so if it's hot i want a red.png and if it's medium it should be green.png and if cold it'll be blue.png

the files already exist and contain 1000's of lines, i just dont have the awk knowledge to manage a quick change

can you please provide some insight?

i was thinking along the lines of this:

awk'/^network type:/{ choose some graphic, like foo=blue.png;}/\<styleUrl\>/{print "  <styleUrl>"foo"</styleUrl>"; next;}{print}'

..but i must include some "if" statements for the different colors, that's where i get lost..

many thanks, G

No thread Hijacking in future and open up your own thread. This has been separated from the other thread. You'll also get a pm for a notice on using code tags.

Here's one way to do it with Perl:

$
$
$ cat -n f0
     1  <Placemark>
     2  network type: hot
     3  line1
     4  line2
     5  line3
     6  <styleUrl>red.png</styleUrl>
     7  </Placemark>
     8  <Placemark>
     9  network type: cold
    10  line1
    11  line2
    12  line3
    13  <styleUrl>red.png</styleUrl>
    14  </Placemark>
    15  <Placemark>
    16  network type: medium
    17  line1
    18  line2
    19  line3
    20  <styleUrl>red.png</styleUrl>
    21  </Placemark>
    22  <Placemark>
    23  network type: something_else
    24  line1
    25  line2
    26  line3
    27  <styleUrl>something_else.png</styleUrl>
    28  </Placemark>
$
$
$ perl -lne '/^network type: (hot|cold|medium)$/ and $x = $1 eq "hot" ? "red.png" : ($1 eq "medium" ? "green.png" : "blue.png");
             if (/(<styleUrl>).*?(<\/styleUrl>)/ and $x ne "") {print "$1$x$2"; $x=""} else {print $_}' f0
<Placemark>
network type: hot
line1
line2
line3
<styleUrl>red.png</styleUrl>
</Placemark>
<Placemark>
network type: cold
line1
line2
line3
<styleUrl>blue.png</styleUrl>
</Placemark>
<Placemark>
network type: medium
line1
line2
line3
<styleUrl>green.png</styleUrl>
</Placemark>
<Placemark>
network type: something_else
line1
line2
line3
<styleUrl>something_else.png</styleUrl>
</Placemark>
$
$

tyler_durden

oops forget it