Jump to content

php - xml


gabhod

Recommended Posts

okey...i have a situation with php - xml...i have an file xml that is like this :

  <?xml version="1.0" encoding="UTF-8" ?> - <REPORT>  <TITLE>REPORT</TITLE> - <BODY>- <HEADER SEQ="1">- <COLUMN>  <SEQ>1</SEQ>   <TITLE>HEADER</TITLE>   </COLUMN>- <COLUMN>  <SEQ>2</SEQ>   <TITLE>HEADER</TITLE>   </COLUMN>+ <COLUMN>  <SEQ>3</SEQ>   <TITLE>COLUMN</TITLE>   </COLUMN>  </HEADER>- <HEADER SEQ="2">- <COLUMN>  <SEQ>1</SEQ>   <TITLE>DATE</TITLE>   </COLUMN>- <COLUMN>  <SEQ>2</SEQ>   <TITLE>NAME</TITLE>   </COLUMN>- <COLUMN>  <SEQ>3</SEQ>   <TITLE>ADRRESS</TITLE>   </COLUMN>  </HEADER>- <DATA>  <QUERY>SELECT * FROM INFORMATION WHERE DATE = ydate</QUERY>   </DATA>  </BODY>  </REPORT>

the problem is :1. can anyone recommend how parse this xml using php 2. can i use php to pass a value so it can be read into ydate from the query on the xml file.3. i'm trying to use this kind of format to make an excel report using php... a php converter excel...something like that i guess...is this possible?thanks before, and sorry for my bad englishps : i'm using php4

Link to comment
Share on other sites

Are those plusses and minuses in the actual file or that just the result of a copy and paste from a GUI?
I'm betting it's the result from copying from IE.
ps : i'm using php4
Say no more. Upgrade to PHP5 first. Then, look at the PHP tutorial from W3School. It covers the basics of three methods with which XML data could be manipulated.Once you extract the data you need, you can use Excel's COM API to write an Excel file based on the gathered data. How exactly do you do that part, I don't know, as I've never created any Office file with PHP.But XML traversal... in PHP4? Forget it.
Link to comment
Share on other sites

Are those plusses and minuses in the actual file or that just the result of a copy and paste from a GUI?
Yup,its result of copy paste from EI
Say no more. Upgrade to PHP5 first. Then, look at the PHP tutorial from W3School. It covers the basics of three methods with which XML data could be manipulated.Once you extract the data you need, you can use Excel's COM API to write an Excel file based on the gathered data. How exactly do you do that part, I don't know, as I've never created any Office file with PHP.But XML traversal... in PHP4? Forget it.
lol...i wish i could use php5...everything would be so easy..not just for XML uses but even for implementing the oracle databse...but unfortunately i have to use php4...I have just able to figure out how to parse the XML...
<?if (!($fp=@fopen("./report_id_1.xml", "r"))) die ("Couldn't open XML.");$usercount=0;$userdata=array();$state='';function startElementHandler ($parser,$name,$attrib){ global $usercount;global $userdata;global $state;$state=$name;}function endElementHandler ($parser,$name){global $usercount;global $userdata;global $state;$state='';if($name=="BODY") {$usercount++;}}function characterDataHandler ($parser, $data) {global $usercount;global $userdata;global $state;if (!$state) {return;}if ($state=="QUERY") { $userdata["query"] = $data;}if ($state=="TITLE") { $userdata[$usercount]["title"] = $data;}if ($state=="HEADER") { $userdata[$usercount]["header"] = $data;}}if (!($xml_parser = xml_parser_create())) die("Couldn't create parser.");xml_set_element_handler( $xml_parser, "startElementHandler", "endElementHandler");xml_set_character_data_handler( $xml_parser, "characterDataHandler");while( $data = fread($fp, 4096)){if(!xml_parse($xml_parser, $data, feof($fp))) {break;}}xml_parser_free($xml_parser);?>

its not fully finished yet....but i think its okey :)Problem 2.I've managed to figure that i could use str_replace to pass the value ydateProblem 3.Now there's still problem 3 :mellow:Maybe from my thread

http://w3schools.invisionzone.com/index.php?showtopic=17300

you could see my problem, i'm still trying to figure out the error...but still accepting anykind of idea or suggestion...thanks guys :)

Link to comment
Share on other sites

Hrmm... XML and PHP 4 aren't a very useful combination.
Hehehee....is PHP4 ever a good combination since PHP5 is out....or is it 6 now?? :)btw....if you can give me some advice on this thread
http://w3schools.invisionzone.com/index.php?showtopic=17300

thanks before...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...