I was trying to do the same thing. I found it easier to convert it to mysql and the pull the information from your mysql server if you have one.
Q1712:
I’m assuming that you didn’t mean to put that extra <?php at the beginning of your code. Anyways, I place the code in a separate file here: http://wow.wolfdragon.net/get_contents.php. And yes, I am using simpleXML, the code for that is contained in the XML.inc.php file. I can post it if needed.
bustersnm:
I have a mysql server. What script did you use to convert it? And does it do it dynamically, because the XML data changes all the time?
I tried using the code that Q1712 wrote in my original file like this:
[code]<?php
error_reporting(E_ALL);
require_once(“XML.inc.php”);
$xml_file=file_get_contents(‘http://wowarmory.com/character-talents.xml?r=Hydraxis&n=Nicora’);
#$xml_data=implode("",file($xml_file)); //get XML data for alternative direct parsing
$xml=new XML();
$xml->file_read($xml_file);
#$xml->parse($xml_data); //parse direct XML data
$xml->parse();
#$xml->debug();
//Samples…
echo $xml;
//echo $xml->page->_param[“lang”];
//echo $xml->page->characterInfo->talentTab->talentTree->_param[“value”];
?>[/code]
So what I’m guessing I should be seeing (actually what I want to see) is the XML just echoed for me. What I get is
Object
Nothing else, not even in the source code.
cause $xml is an object (an instance of a class), not a string.
but it seems that the data is recived properly.
i thing would be good if we could have a look at the XML.inc.php
Here it is:
[code]<?php
/*
- XML.inc.php
- Class to convert an XML file into an object
- Copyright © 2006 Oliver Strecke [email protected]
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
class XML{
var $_parser;
var $_xml_data;
var $_actual_tag;
//Constructor...
function xml(){
$this->_parser=xml_parser_create("ISO-8859-1");
$this->_xml_data="";
$this->_actual_tag=$this;
xml_set_object($this->_parser,$this);
xml_parser_set_option($this->_parser,XML_OPTION_CASE_FOLDING,false);
xml_set_element_handler($this->_parser,"tag_open","tag_close");
xml_set_character_data_handler($this->_parser,"tag_data");
xml_set_default_handler($this->_parser,"tag_data");
}
//get XML data from file...
function file_read($xml_file){
if(file_exists($xml_file)){
$this->_xml_data=implode("",file($xml_file));
}
return 1;
}
//parse XML data...
function parse($xml_data=0){
if($xml_data)$this->_xml_data=$xml_data;
xml_parse($this->_parser,$this->_xml_data);
xml_parser_free($this->_parser);
return 1;
}
function tag_open($parser,$name,$attrs){
//create new tag...
$tag=new XML_TAG(&$this->_actual_tag);
$tag->_name=$name;
$tag->_param=$attrs;
//add tag object to parent/actual tag object...
if(is_a($this->_actual_tag,"XML_TAG")){
if(is_object($this->_actual_tag->$name) || is_array($this->_actual_tag->$name)){
//same child objects -> Array...
$last_index=$this->_actual_tag->new_child_array($tag,$name);
$this->_actual_tag=&$this->_actual_tag->{$name}[$last_index];
}else{
//add new child object to actual tag...
$this->_actual_tag->new_child($tag,$name);
$this->_actual_tag=&$this->_actual_tag->$name;
}
}else{
//copy first tag object in this object...
$this->$name=$tag;
$this->_actual_tag=&$this->{$name};
}
return 1;
}
function tag_data($parser,$string){
if(strlen(trim($string))>0)$this->_actual_tag->_value=$string;
return 1;
}
function tag_close($parser,$name){
$this->_actual_tag=&$this->_actual_tag->_parent;
return 1;
}
//Debug...
function debug($exit=0){
echo "<pre>";
print_r($this);
echo "</pre>";
if($exit)exit;
}
}
class XML_TAG{
var $_parent;
var $_name;
var $_value;
var $_param;
//Constructor...
function xml_tag($parent){
$this->_parent=&$parent;
$this->_name="";
$this->_value=false;
$this->_param=Array();
return 1;
}
//simply add ne child to this object...
function new_child($child,$child_name){
$this->$child_name=&$child;
}
//add child array for more same childs to this object...
function new_child_array($child,$child_name){
//create array and set old child object to the first array element...
if(is_object($this->$child_name)){
$tmp_obj=$this->$child_name;
$this->$child_name=Array();
$this->new_child_array($tmp_obj,$child_name);
}
//push child reference into child array...
$this->{$child_name}[]=&$child;
$last_index=count($this->$child_name)-1;
return $last_index;
}
//Debug...
function debug(){
echo "<pre>";
print_r($this);
echo "</pre>";
}
}
?>[/code]
//get XML data from file... function file_read($xml_file){ if([b]file_exists($xml_file)[/b]){ $this->_xml_data=implode("",file($xml_file)); } return 1; }
file_exists dosn’t work with URL’s.
thats why using this class with url will fail.
u may wanna contact the author about that.
I use the ExcelMySQLConverter from soft galexy, to convert to a sql. then you just upload it into your mysql.
that is why Q i need help with that codeing
Is there something I can use instead of file_exists that will work with URLs?
Thanks, but I was looking for something I wouldn’t have to buy. If it comes down to it, I’ll reconsider it.
delete the if. but than u have to be sure the url is woking or have to catch the xml-parse-error.
So I removed the if statement
//get XML data from file...
function file_read($xml_file){
$this->_xml_data=implode("",file($xml_file));
return 1;
}
And I get this: http://wow.wolfdragon.net/test.php
It’s not quite working yet.
i guess u now passes the already loaded xmldata to the file_read() function.
file_read() needs a filename/url as argument.
now that u deleted the if, try the code u used in the very beginning.
So I changed the code back to this:
[code]<?php
require_once(“XML.inc.php”);
$xml_file=“http://wowarmory.com/character-talents.xml?r=Hydraxis&n=Nicora”;
#$xml_data=implode("",file($xml_file)); //get XML data for alternative direct parsing
$xml=new XML();
$xml->file_read($xml_file);
#$xml->parse($xml_data); //parse direct XML data
$xml->parse();
#$xml->debug();
//Samples…
echo $xml->page->_param[“lang”];
echo $xml->page->characterInfo->talentTab->talentTree->_param[“value”];
?>[/code]
And all I get is a blank page again: http://wow.wolfdragon.net/test.php
add error_reporting(E_ALL)
Okay, I talked to my host and she told me how to use PHP5 on my server so I was able to use the built-in SimpleXML (thank god, because the code is so much simpler). Here’s my code:
[code]<?php
echo error_reporting(E_ALL);
$xml = file_get_contents(‘http://wowarmory.com/character-talents.xml?r=Hydraxis&n=Nicora’);
$page = simplexml_load_file(’$xml’);
echo $page->characterInfo->talentTab->talentTree[‘value’];
?>[/code]
And it outputs this: 6143 (for the error code)
http://wow.wolfdragon.net/simple-test.php5
[php]<?php
error_reporting(E_ALL);
$xml = file_get_contents(‘http://wowarmory.com/character-talents.xml?r=Hydraxis&n=Nicora’);
$page = simplexml_load_file(’$xml’);
echo $page->characterInfo->talentTab->talentTree[‘value’];
?>[/php]
but i cant see the page http://wowarmory.com/character-talents. … s&n=Nicora having infos in characterInfo->talentTab->talentTree.
it a xhtml page.
So…I’m using the wrong script?
i think u are using the wrong xml file.
I think you’re right. It seems that as the script is bringing the XML file in, it somehow becomes HTML. So, instead of parsing XML, I need to be parsing HTML. Back to the drawing board. I’ll look for some scripts for that on my own but any suggestions you have would be really appreciated.
it’s xhtml.
xhtml is xml as well.
u may use that script u have.
just adjust the location u are looking at. $page->body->…