www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-06-2009, 10:45 PM
    benbramz benbramz is offline
    Registered User
     
    Join Date: May 2005
    Posts: 49
    weird named array key causing problems

    hi all

    Im using the simplexml_load_file function here.

    There is an attribute in the xml named @attributes which but in using the code below:

    $stat = $xml->@attributes->stat;

    throws me an error, of course, unexpected '@'. How can i get around this?
    Reply With Quote
      #2  
    Old 11-07-2009, 12:13 PM
    GUIR's Avatar
    GUIR GUIR is offline
    A Really Simple Stupid
     
    Join Date: Sep 2004
    Location: Sri Lanka
    Posts: 382
    What about replacing @attribute with another before parsing..

    $xml = str_replace('@attributes','a_t_attributes',$xml);

    $stat = $xml->a_t_attributes->stat;
    Reply With Quote
      #3  
    Old 11-07-2009, 12:56 PM
    NogDog's Avatar
    NogDog NogDog is online now
    High Energy Magic Dept.
     
    Join Date: Aug 2004
    Location: Ankh-Morpork
    Posts: 13,641
    I believe the "@" is an artifact of simpleXML, not part of the actual XML data being parsed. You should be able to access an attribute directly from the element, e.g.: $xml->elementName['attributeName']. See "Example #5" on the SimpleXML Examples page.
    __________________
    "That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett
    freelancer.internet.com
    Email me
    Reply With Quote
      #4  
    Old 11-07-2009, 08:35 PM
    benbramz benbramz is offline
    Registered User
     
    Join Date: May 2005
    Posts: 49
    I think your right that the '@' is from the simple xml..

    However im still none the wiser to how i can access the data. A print_r() of the whole simpleXML read is as folllows...

    Code:
    SimpleXMLElement Object ( [@attributes] => Array ( [stat] => ok ) 
    [auth] => SimpleXMLElement Object ( [token] => xxx [perms] => x [user] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => x [username] => x [fullname] => xx ) ) ) )
    any more help?

    edit:

    Heres the actual xml i get back..
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <rsp stat="ok"><auth><token>xxx</token><perms>x</perms><user id="x" username="x" fullname="xx"/></auth></rsp>

    Last edited by benbramz; 11-07-2009 at 08:40 PM. Reason: adding xml
    Reply With Quote
      #5  
    Old 11-07-2009, 09:05 PM
    benbramz benbramz is offline
    Registered User
     
    Join Date: May 2005
    Posts: 49
    Quote:
    Originally Posted by NogDog View Post
    I believe the "@" is an artifact of simpleXML, not part of the actual XML data being parsed. You should be able to access an attribute directly from the element, e.g.: $xml->elementName['attributeName']. See "Example #5" on the SimpleXML Examples page.
    NogDog, sorry.

    I didnt get at first what you meant, but now the penny just dropped. Thanks a lot!
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 11:34 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.