Kod
<?xml version="1.0"?>
<ids>
<id>One</id>
<id type="2">Two</id>
<id type="3">Three</id>
<id type="4">Four</id>
<id type="5">Five</id>
<id type="6">Six</id>
</ids>
<ids>
<id>One</id>
<id type="2">Two</id>
<id type="3">Three</id>
<id type="4">Four</id>
<id type="5">Five</id>
<id type="6">Six</id>
</ids>
php:
Kod
<?php
$xml = simplexml_load_file("test.xml");
$xml->id[0]->addAttribute("type", "1");
$xml->asXML("test.xml");
?>
$xml = simplexml_load_file("test.xml");
$xml->id[0]->addAttribute("type", "1");
$xml->asXML("test.xml");
?>
wynik xml'a :
Kod
<?xml version="1.0"?>
<ids>
<id type="1">One</id>
<id type="2">Two</id>
<id type="3">Three</id>
<id type="4">Four</id>
<id type="5">Five</id>
<id type="6">Six</id>
</ids>
<ids>
<id type="1">One</id>
<id type="2">Two</id>
<id type="3">Three</id>
<id type="4">Four</id>
<id type="5">Five</id>
<id type="6">Six</id>
</ids>
i nie wiem jak to przerobić żeby do takiego xml'a:
Kod
<?xml version="1.0"?>
<ad num="126" type="0" time="6900">
<ids>
<id type="1"/>
<id type="2"/>
</ids>
</ad>
<ad num="126" type="0" time="6900">
<ids>
<id type="1"/>
<id type="2"/>
</ids>
</ad>
Dodało atrybut (web) w tym miejscu :
Kod
<?xml version="1.0"?>
<ad num="126" type="0" time="6900" web="">
<ids>
<id type="1"/>
<id type="2"/>
</ids>
</ad>
<ad num="126" type="0" time="6900" web="">
<ids>
<id type="1"/>
<id type="2"/>
</ids>
</ad>
Ciagle jak prubuje coś zrobić wyrzuca mi błąd :
Fatal error: Call to a member function addAttribute() on a non-object in
Prosze o pomoc..