Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    96
    Thanks
    11
    Thanked 0 Times in 0 Posts

    XML getting a value

    Hi,

    I've not really worked with XML and PHP before and am having what is probably a very simple problem.

    I have the following code:

    Code:
    object(SimpleXMLElement)[69]
      public 'p' => 
        array
          0 => string ' SEQ ' (length=5)
          1 => string ' BQ? BIWOW ' (length=11)
          2 => string ' see amm accunmulafed, ' (length=23)
          3 => string ' Scotland will see snow accumulated, ' (length=37)
          4 => string ' and whilst we will seek rain ' (length=30)
          5 => string ' showers across western Wales and ' (length=34)
          6 => string ' England, most is away from the ' (length=32)
          7 => string ' coastal fringes and it is a fine ' (length=34)
          8 => string ' day. Mainly like winds. ' (length=25)
    Which is taken from the following xml doc:

    Code:
    <div xml:lang="en">
    <p begin="0.08"> SEQ </p>
    <p begin="0.20"> BQ? BIWOW </p>
    <p begin="1.84"> see amm accunmulafed, </p>
    <p begin="2.84"> Scotland will see snow accumulated, </p>
    <p begin="2.84"> and whilst we will seek rain </p>
    <p begin="4.16"> showers across western Wales and </p>
    <p begin="6.44"> England, most is away from the </p>
    How do I get that into a php array where I have the begin value too?

    I've tried some tutorials but they make no sense

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I don't do any work involving the simpleXMLElement's, but the API specifies that the attributes are not shown while examining the object (print_r and var_dump for examples).
    Check this link for retrieving all the attributes from a SimpleXMLElement:
    http://php.ca/manual/en/simplexmlelement.attributes.php

    Alternatively, the DOM allows you to specify which attribute you want to target (while getting a full list is more complicated than the simplexml approach).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $abc=new XMLReader();
    $abc->XML($xml);
    $abc->read();
    $abc->read();
    $temparr=array();
    while($abc->next("p"))
    $temparr[$abc->getAttribute("begin")]=$abc->readString();


    what about trying XMLReader


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •