renaming <tag?>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • newsreader

    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>whate ver</fieldone>
    <fieldtwo>where ver</fieldtwo>
    </row>
    </root>
    ..
    ..
    ..

    Regards to the reader.

  • TheTeapot

    #2
    Re: renaming &lt;tag?&gt;

    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

    Comment

    • newsreader

      #3
      Re: renaming &lt;tag?&gt;

      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($filen ame));
      $simple = $contents;
      $p = xml_parser_crea te();
      xml_parse_into_ struct($p, $simple, $index);
      xml_parser_free ($p);
      for ($i=0; $i <= count($index); $i++) {
      if (is_numeric($in dex[$i]['value']) and (($index[$i]['level']) == 3))
      {
      echo "<un>".$ind ex[$i]['value']."</un>";
      } elseif (is_string($ind ex[$i]['value']) and ($index[$i]['level'] ==
      3)) {
      echo "<description>" .$index[$i]['value']."</description>";
      }
      }

      Thanks for the suggestion.
      regards.

      Comment

      Working...