DOMXML get unknown Attributes

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

    DOMXML get unknown Attributes

    Hey List,

    I was wondering how I can get all Attributes of a XML-Tag without
    knowing them. The XML could look like following:

    <plugin>
    <args level="1" depth="2"/>
    </plugin>
    <plugin>
    <args permission="23"/>
    </plugin>

    Now both plugins use different Attributes in the args tags and the
    program doesn't know them. Is there a way to get them? Put them into
    an array? I am using PHP5
    Thanks a lot and best regards,

    Nikolai Onken
  • Janwillem Borleffs

    #2
    Re: DOMXML get unknown Attributes

    Nikolai Onken wrote:[color=blue]
    > Now both plugins use different Attributes in the args tags and the
    > program doesn't know them. Is there a way to get them? Put them into
    > an array? I am using PHP5
    > Thanks a lot and best regards,
    >[/color]

    Since the DOM function DocumentElement ::getAttributes () doesn't seem to be
    implemented, you could, per example, use the simplexml extension instead:

    <?php

    $xml = <<<EOXML
    <plugins>
    <plugin>
    <args level="1" depth="2"/>
    </plugin>
    <plugin>
    <args permission="23"/>
    </plugin>
    </plugins>
    EOXML;

    $dom = new DomDocument;
    $dom->loadXML($xml );

    $s = simplexml_impor t_dom($dom);

    foreach ($s->plugin as $plugin) {
    foreach($plugin->args[0]->attributes() as $n => $v) {
    print "$n => $v<br />";
    }
    }

    ?>


    HTH;
    JW



    Comment

    • Simon Stienen

      #3
      Re: DOMXML get unknown Attributes

      Nikolai Onken <info@nikolaion ken.com> wrote:[color=blue]
      > Hey List,
      >
      > I was wondering how I can get all Attributes of a XML-Tag without
      > knowing them. The XML could look like following:
      >
      > <plugin>
      > <args level="1" depth="2"/>
      > </plugin>
      > <plugin>
      > <args permission="23"/>
      > </plugin>
      >
      > Now both plugins use different Attributes in the args tags and the
      > program doesn't know them. Is there a way to get them? Put them into
      > an array? I am using PHP5
      > Thanks a lot and best regards,
      >
      > Nikolai Onken[/color]

      Since the XML-document should follow a specific DTD, you should know
      *every* possible attribute. If you are just beginning to create such a
      structure, maybe you can change it to something like:

      <plugin>
      <arg name="level" value="1" />
      <arg name="depth" value="2" />
      </plugin>
      <plugin>
      <arg name="permissio n" value="23" />
      </plugin>


      --
      Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
      »What you do in this world is a matter of no consequence,
      The question is, what can you make people believe that you have done.«
      -- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle

      Comment

      • Nikolai Onken

        #4
        Re: DOMXML get unknown Attributes

        On Thu, 23 Sep 2004 08:57:50 +0200, Simon Stienen
        <simon.stienen@ news.slashlife. de> wrote:
        [color=blue]
        ><plugin>
        > <arg name="level" value="1" />
        > <arg name="depth" value="2" />
        ></plugin>
        ><plugin>
        > <arg name="permissio n" value="23" />
        ></plugin>[/color]

        Hey Simon,

        I was thinking about that and its true - otherwise the idea of XML
        wouldn't really be followed... I'll use the name="" value="" instead.
        Thanks for your help!
        Regards,

        Nikolai

        Comment

        Working...