|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
So here's my problem. I have 3 xml files. The first holds the other two, think of a table of contents, via entities. When I use print_r to display output I receive what I want, plus an extra iteration of the last entity. ??? I don't know why this is happening, my code is below, please help.
main.htm PHP Code:
main.xml PHP Code:
test1.xml & test2.xml - Just switch all the 1's to 2's PHP Code:
|
|
#2
|
|||||
|
|||||
|
Hey, XML is case-sensitive, so how about this?
xml Code:
Output: Code:
C:\Work\scrap\test>php -f main.php
SimpleXMLElement Object
(
[test1] => SimpleXMLElement Object
(
[test1] => SimpleXMLElement Object
(
[section] => SimpleXMLElement Object
(
[@attributes] => Array
(
[title] => Test 1
[location] => ../xml/t1/test1.xml
)
[page] => SimpleXMLElement Object
(
[@attributes] => Array
(
[location] => test1.php
)
)
)
)
[test2] => SimpleXMLElement Object
(
[section] => SimpleXMLElement Object
(
[@attributes] => Array
(
[title] => Test 2
[location] => ../xml/t1/test2.xml
)
[page] => SimpleXMLElement Object
(
[@attributes] => Array
(
[location] => test2.php
)
)
)
)
)
[test2] => SimpleXMLElement Object
(
[test2] => SimpleXMLElement Object
(
[section] => SimpleXMLElement Object
(
[@attributes] => Array
(
[title] => Test 2
[location] => ../xml/t1/test2.xml
)
[page] => SimpleXMLElement Object
(
[@attributes] => Array
(
[location] => test2.php
)
)
)
)
)
)
|
|
#3
|
|||
|
|||
|
Sorry, this was not directly copied from actual source code, it's for work and they frown on that
. This is merely redone from memory, nice catch though . And that is the exact output I get. As you can see there is [test1] and [test2] data in the first [test1] array and then a second separate [test2] array with the [test2] data. There should only be two outputs. |
|
#4
|
|||||
|
|||||
|
Sorry, I guess I got distracted by the shiny object of run-time errors and totally lost your question/problem!
Weird. Could be a bug in the SimpleXML parser, I guess. I tried it in C# with some pretty basic code, and it seems OK: c# Code:
Output: |
|
#5
|
|||
|
|||
|
I've only vaguely looked into c/c++/c# and that was over 3 years ago so I don't remember too much about it
However if this works, this may be the route I have to go. Is there anyway to check if it is the parser? I'd hate to add another language to my list at the moment as I'm already in the middle of learning 3 others (PHP, XML, and MySQL) More than willing to look into it later though Thanks for all your help, this is the third forum I've posted this on and you're the only one who's answered thus far. Thank you very much! |
|
#6
|
|||||
|
|||||
|
Figured it out...provided your version of PHP > 5.1.0 and libxml > 2.6.0:
Calling simplexml_load_file like this: php Code:
Gave this output: Code:
ptr2void@home:~/scrap/xmltest> php -f main.php
SimpleXMLElement Object
(
[section] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[title] => Test 1
[location] => ../xml/t1/test1.xml
)
[page] => SimpleXMLElement Object
(
[@attributes] => Array
(
[location] => test1.php
)
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[title] => Test 2
[location] => ../xml/t2/test2.xml
)
[page] => SimpleXMLElement Object
(
[@attributes] => Array
(
[location] => test2.php
)
)
)
)
)
Last edited by ptr2void : September 14th, 2008 at 06:50 PM. |
|
#7
|
|||
|
|||
|
Wow, thank you so much. That is the exact outcome I needed. I have PHP 5.2 at work, though I'm not sure about XML as I didn't have to set anything up for that. I'll try it when I get back to work tomorrow.
If everything goes well this will have saved me months of hard work and finally make my job that cushy desk job I always wanted More time to spend learning more material. Thanks ever so much again! |
|
#8
|
|||
|
|||
|
Oh, one quick other question. I noticed you posted the load file syntax as: simplexml_load_file.
The books and tutorials I have showed it as: simple_xml_loadfile. Was this a typo or is this just an alternative? Thanks again! |
|
#9
|
|||
|
|||
|
Cool, glad I could help! I'm guessing if you're running 5.2, the libxml version against which it was compiled is probably newer than 2.6, as 2.6.0 came out in late 2003. Hopefully no worries for you.
|
|
#10
|
|||
|
|||
|
Problem Solved
That did the trick. Thanks again, and you can ignore the other question, I was merely looking at my own code wrong
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Completely lost - SimpleXML(PHP) entity problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|