ukweb Posted March 8, 2011 Share Posted March 8, 2011 Hi I'm using SimpleXMLElement to work with a supplied XML file, problem is with the way the XML document is formatted. The document uses '-' (minus) in the element names instead of _ so when I go to read the values, nothing is returned: $developer->developer-region; //returns nothing However if I change the sample XML document that I've been supplied to <developer_region></developer_region> and do $developer->developer_region; //returns child elements This is not practical to manually change the document, is there a way to use '-' in the xml document? Thanks in advance Ste Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/ Share on other sites More sharing options...
salathe Posted March 8, 2011 Share Posted March 8, 2011 See example #3 on http://php.net/simplexml.examples-basic Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184436 Share on other sites More sharing options...
ukweb Posted March 8, 2011 Author Share Posted March 8, 2011 See example #3 on http://php.net/simplexml.examples-basic Muchos appreciation! use the old {}, saved me a lot of headache, thanks again man! :-) Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184441 Share on other sites More sharing options...
salathe Posted March 8, 2011 Share Posted March 8, 2011 Now that I know you've read the manual () I'll copy the answer into here for any future visitors having the same issue (if you do, go read the manual page!). Accessing elements within an XML document that contain characters not permitted under PHP's naming convention (e.g. the hyphen) can be accomplished by encapsulating the element name within braces and the apostrophe. Example #3 Getting <line> <?php include 'example.php'; $xml = new SimpleXMLElement($xmlstr); echo $xml->movie->{'great-lines'}->line; ?> The above example will output: PHP solves all my web problems P.S. Don't forget to mark the thread as "solved" Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184446 Share on other sites More sharing options...
ukweb Posted March 8, 2011 Author Share Posted March 8, 2011 Will do, looking for the "solved" button! Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184503 Share on other sites More sharing options...
Maq Posted March 8, 2011 Share Posted March 8, 2011 Will do, looking for the "solved" button! We recently updated the forums and the Topic Solved mod hasn't been implemented yet. Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184521 Share on other sites More sharing options...
salathe Posted March 8, 2011 Share Posted March 8, 2011 Ooh, I totally missed that the button has gone walkabout. Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184571 Share on other sites More sharing options...
Maq Posted March 8, 2011 Share Posted March 8, 2011 Ooh, I totally missed that the button has gone walkabout. Figured as much Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184589 Share on other sites More sharing options...
salathe Posted March 8, 2011 Share Posted March 8, 2011 It would have been nice to announce this sort of thing; mostly to show that the place is being looked after, but also to celebrate the awesome new features available (are there any?). P.S. Apologies for wandering off topic! Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184627 Share on other sites More sharing options...
kenrbnsn Posted March 8, 2011 Share Posted March 8, 2011 The forum upgrade was announced here Ken Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184634 Share on other sites More sharing options...
salathe Posted March 8, 2011 Share Posted March 8, 2011 The forum upgrade was announced here Urgh, why make it in entirely the wrong forum? I guess it slipped under my radar (was on vacation ) and I would never have thought to look in there for an announcement! Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184640 Share on other sites More sharing options...
Maq Posted March 8, 2011 Share Posted March 8, 2011 The forum upgrade was announced here Urgh, why make it in entirely the wrong forum? I guess it slipped under my radar (was on vacation ) and I would never have thought to look in there for an announcement! Because I think he was looking for Questions, Comments, and Suggestions for the new upgrade. Quote Link to comment https://forums.phpfreaks.com/topic/229973-use-of-minus-with-xml/#findComment-1184676 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.