Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php,xml] Dodawanie atrybutu..
JeFF
post
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 16.06.2008

Ostrzeżenie: (0%)
-----


test.xml :
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>


php:
Kod
<?php
     $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>


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>


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>


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..
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 15:35