Jump to content

[SOLVED] PHP5 DOM XML Query


JonnyThunder

Recommended Posts

Hello all!  First time poster on here, hope you can help me out.

Here is my code.  When run, it displays nothing!  Why doesn't it show the ID attribute as I would expect....

 

    $str = '<?xml version="1.0" encoding="iso-8859-1"?>

    <FORM>
        <FIELD ID="fld_inputbox">
            <TYPE>inputbox</TYPE>
            <MAXCHARS>20</MAXCHARS>
            <DISPLAYCHARS>10</DISPLAYCHARS>
            <DEFAULTVALUE>Hello World</DEFAULTVALUE>
        </FIELD>
        <FIELD ID="fld_dropdown">
            <TYPE>dropdown</TYPE>
            <OPTION>
                <LABEL>Option 1</LABEL>
                <VALUE>1</VALUE>
            </OPTION>
            <OPTION>
                <LABEL>Option 2</LABEL>
                <VALUE>2</VALUE>
            </OPTION>
        </FIELD>
    </FORM>
    
    ';


    $doc  = new DOMDocument();
    $doc -> loadXML($str);
    
    $fields = $doc->getElementsByTagName( "FIELD" );
    
    foreach( $fields as $field )
    {
        print $field->getAttribute['ID'];
    }

 

I'd expect it to show fld_inputbox and fld_dropdown but I get absolutely nothing!

 

Any pointers greatly appreciated,

JT

Link to comment
https://forums.phpfreaks.com/topic/114542-solved-php5-dom-xml-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.