Connecting Tech Pros Worldwide Help | Site Map

renaming <tag?>

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 13th, 2006, 02:45 AM
newsreader
Guest
 
Posts: n/a
Default renaming <tag?>

X-No-Archive

How do I quickly rename xml tags enmass without altering the contents
of the tag?

eg.

from:

<root>
<row>
<field>whatever</field>
<field>wherever</field>
</row>
..
..
..
</root>

to:

<root>
<row>
<fieldone>whatever</fieldone>
<fieldtwo>wherever</fieldtwo>
</row>
</root>
..
..
..

Regards to the reader.


  #2  
Old May 13th, 2006, 04:45 AM
TheTeapot
Guest
 
Posts: n/a
Default Re: renaming <tag?>

This is PHP?? I don't think so. If you told us something like your
name so we can talk to you, or what software you are using or something
like that, then we might be able to help you.

preg_replace might help, if I understand your problem correctly (but I
can't be sure, so I haven't given a full example).

TheTeapot

  #3  
Old May 13th, 2006, 07:45 AM
newsreader
Guest
 
Posts: n/a
Default Re: renaming <tag?>

TheTeapot wrote:[color=blue]
> This is PHP?? I don't think so. If you told us something like your
> name so we can talk to you, or what software you are using or something
> like that, then we might be able to help you.
>
> preg_replace might help, if I understand your problem correctly (but I
> can't be sure, so I haven't given a full example).
>
> TheTeapot[/color]

It's cool, I sort of hacked together a solution that did the job. It
might not be the best
code but it worked. I had to replace the first <field> with <un> and
the second <field>
with <description>.

$filename = "dg3.xml";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
$simple = $contents;
$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $index);
xml_parser_free($p);
for ($i=0; $i <= count($index); $i++) {
if (is_numeric($index[$i]['value']) and (($index[$i]['level']) == 3))
{
echo "<un>".$index[$i]['value']."</un>";
} elseif (is_string($index[$i]['value']) and ($index[$i]['level'] ==
3)) {
echo "<description>".$index[$i]['value']."</description>";
}
}

Thanks for the suggestion.
regards.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.