[PHP] XML to ARRAY
Here is a piece of code, that is close to doing what I want it to. The end result I would like to have is an array that is simple to work with. If the XML tag was RED HAT, I would like something like the following: $Tags['issue-name']. So I could print it out. Something like, print "$Tags['issue-name']\n"; I was able to get a numerical representation of the array like, $Tags[5] and the value of that tag was "RED HAT", but then I would have to know what the position of the data I am looking for in the array. I would prefer to know the tag name and the array and get to the data that way. I know there is a way to do this, but I just can't figure it out. There is a lot of information on Parsing the XML file but not getting into a useful array, or at least that I have found easily to understand. if(!isset($Sym)) { $Sym = 'IKN'; } $URI = 'http://quotes.nasdaq.com/quote.dll?page=xml&mode=stock&symbol='; $simple = implode( '', file("$URI$Sym")); $p = xml_parser_create(); xml_parse_into_struct($p,$simple,$vals,$index); xml_parser_free($p); file://echo "Index array\n"; file://print_r($index); file://echo "\nVals array\n"; file://print_r($vals); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] xml to array
Joe Shmoe foo bar <0>DNR <1>OPT <2>FOO <3>BAR <4>CWS <5>AVS 72 96Kg 0 etc... $xml_data = $xml; $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); xml_parse_into_struct($parser, $xml_data, &$values, &$tags); xml_parser_free($parser); each time I print out the tags or vals it stops at the options node: [13] => Array ( [tag] => OPTIONS [type] => open [level] => 3 [value] => ) [OPTIONS] => Array ( [0] => 13 ) Something to do with the numerical node names..?? If I change them to non-numeric vals all is good... What Am I missing?? -B -- s/:-[(/]/:-)/g BrianGnuPG -> KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu == gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC Key Info: http://gfx-design.com/keys Linux Registered User #339825 at http://counter.li.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] 'XML To Array' Class
Hello, I'm new to using XML with PHP, but I think I've got it figured out for the most part. I have created a class that reads in an XML file and returns the data it finds to an array, but I'm running into a problem because the array keeps coming back empty. Would you mind taking a moment to see where I'm going wrong? file.xml === /article1.html Article 1 /article2.html Article 2 xml.class.php === Parser = xml_parser_create("ISO-8859-1"); xml_set_object($this->Parser, &$this); xml_set_element_handler($this- >Parser, "Tag_Open", "Tag_Close"); xml_set_character_data_handler($this- >Parser, "CData"); $this->theArray = array(); $this->theArrayPointer = 0; $this->theArrayGetElement = NULL; $this->theArrayTopElement = $_PARENT_; $this->theArrayElements = $_CHILDREN_; } function Free() { xml_parser_free($this->Parser); } function Parse_Array($_FILE_) { $_FP_ = fopen($_FILE_, "r") or die("Cannot Open XML Stream"); while ($_DATA_ = fread($_FP_, 4096)) { if (!xml_parse($this->Parser, $_DATA_, feof($_FP_))) { return(FALSE); } } fclose($_FP_); var_dump($this->theArray); return($this->theArray); } function Tag_Open($_PARSER_, $_TAG_, $_ATTR_) { if ($_TAG_ == $this->theArrayTopElement) { $this->theArray[$this->theArrayPointer] = "SOMETEXT"; // NOT SURE IF THIS IS NECESSARY } $_ELEMENTS_ = explode("::", $this- >theArrayElements); for ($I = 0; $I < count($_ELEMENTS_); $I++) { if ($_TAG_ == $_ELEMENTS_[$I]) { $this->theArrayGetElement = $_ELEMENTS_[$I]; } } } function Tag_Close($_PARSER_, $_TAG_) { if ($_TAG_ == $this->theArrayTopElement) { $this->theArrayPointer++; } $this->theArrayGetElement = NULL; } function CData($_PARSER_, $_CDATA_) { if ($this->theArrayGetElement != NULL) { array_push($this->theArray, $_CDATA_); $this->theArray[$this->theArrayPointer] [$this->theArrayGetElement] = $_CDATA_; } } } ?> xml.test.php === Parse_Array("file.xml"); print_r($ARTICLES); ?> What I expect to happen is this: $ARTICLES[0]["URL"] == "/article1.html"; $ARTICLES[0]["TITLE"] == "Article 1"; $ARTICLES[1]["URL"] == "/article2.html"; $ARTICLES[1]["TITLE"] == "Article 2"; But the array is empty. Thankz in advance for your help. Robert -- [ Swift eNetwork ] Matrix http://matrix.swifte.net/ -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] XML to Array
On 10/03/2013 11:47, Karl DeSaulniers wrote: Hi Guys, I am hoping someone can guide me or help me fix this issue. I have been lost in the code for some time now. I am trying to get the attributes of an xml node. I have this code: [snip] this may help -> http://stackoverflow.com/questions/1156957/php-xml-attribute-parsing I do admit I haven't the foggiest idea what I am doing here, so I am noobing out here on how this php function is really working. I got it off php.net and am trying to implement it in my code. Without my addition it works well except it doesn't grab any attributes which I need in order for my script to work properly. Any ideas on what I am doing wrong? TIA, HTH rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML to Array
On Mar 10, 2013, at 6:03 AM, richard gray wrote: On 10/03/2013 11:47, Karl DeSaulniers wrote: Hi Guys, I am hoping someone can guide me or help me fix this issue. I have been lost in the code for some time now. I am trying to get the attributes of an xml node. I have this code: [snip] this may help -> http://stackoverflow.com/questions/1156957/php-xml-attribute-parsing I do admit I haven't the foggiest idea what I am doing here, so I am noobing out here on how this php function is really working. I got it off php.net and am trying to implement it in my code. Without my addition it works well except it doesn't grab any attributes which I need in order for my script to work properly. Any ideas on what I am doing wrong? TIA, HTH rich Thanks rich, That uses simpleXML. I am using xml_parse_create. Any ideas for xml_parse_create? I really like the way this function puts everything into an array that I can traverse. I only need it to put the attribute values in the array for the corresponding node and I am done. *Sigh Thanks for your help, Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML to Array
On Sun, Mar 10, 2013 at 6:28 PM, Karl DeSaulniers wrote: > > On Mar 10, 2013, at 6:03 AM, richard gray wrote: > >> On 10/03/2013 11:47, Karl DeSaulniers wrote: >>> >>> Hi Guys, >>> I am hoping someone can guide me or help me fix this issue. >>> I have been lost in the code for some time now. >>> I am trying to get the attributes of an xml node. >>> I have this code: >>> [snip] >> >> this may help -> >> http://stackoverflow.com/questions/1156957/php-xml-attribute-parsing >>> >>> I do admit I haven't the foggiest idea what I am doing here, so I am >>> noobing out here on how this php function is really working. >>> I got it off php.net and am trying to implement it in my code. Without my >>> addition it works well except it doesn't grab any attributes >>> which I need in order for my script to work properly. >>> >>> Any ideas on what I am doing wrong? >>> >>> TIA, >> >> >> HTH >> rich > > > > Thanks rich, > That uses simpleXML. I am using xml_parse_create. > Any ideas for xml_parse_create? I really like the way this function > puts everything into an array that I can traverse. I only need it to put > the attribute values in the array for the corresponding node and I am done. > *Sigh > > Thanks for your help, > > Best, > > > Karl DeSaulniers > Design Drumm > http://designdrumm.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > I came across this XML to JSON to an array some time ago. It might be something function xmlToArray($xml) { return json_decode(json_encode((array) simplexml_load_string($xml)),1); } -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML to Array
On Mar 11, 2013, at 8:22 AM, Bastien Koert wrote: On Sun, Mar 10, 2013 at 6:28 PM, Karl DeSaulniers > wrote: On Mar 10, 2013, at 6:03 AM, richard gray wrote: On 10/03/2013 11:47, Karl DeSaulniers wrote: Hi Guys, I am hoping someone can guide me or help me fix this issue. I have been lost in the code for some time now. I am trying to get the attributes of an xml node. I have this code: [snip] this may help -> http://stackoverflow.com/questions/1156957/php-xml-attribute-parsing I do admit I haven't the foggiest idea what I am doing here, so I am noobing out here on how this php function is really working. I got it off php.net and am trying to implement it in my code. Without my addition it works well except it doesn't grab any attributes which I need in order for my script to work properly. Any ideas on what I am doing wrong? TIA, HTH rich Thanks rich, That uses simpleXML. I am using xml_parse_create. Any ideas for xml_parse_create? I really like the way this function puts everything into an array that I can traverse. I only need it to put the attribute values in the array for the corresponding node and I am done. *Sigh Thanks for your help, Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I came across this XML to JSON to an array some time ago. It might be something function xmlToArray($xml) { return json_decode(json_encode((array) simplexml_load_string($xml)), 1); } -- Bastien Cat, the other other white meat Thanks Bastien! That worked very well. I now see the attributes. However it does not load the root node? I am going to need that node to display too. Any thoughts as to why it is not showing? I just copied and pasted your code. I'm going to look at some docs to see if I can find out why, but if you know, please let me know your solution. Thanks again. Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML to Array
On Mar 11, 2013, at 8:22 AM, Bastien Koert wrote: On Sun, Mar 10, 2013 at 6:28 PM, Karl DeSaulniers > wrote: On Mar 10, 2013, at 6:03 AM, richard gray wrote: On 10/03/2013 11:47, Karl DeSaulniers wrote: Hi Guys, I am hoping someone can guide me or help me fix this issue. I have been lost in the code for some time now. I am trying to get the attributes of an xml node. I have this code: [snip] this may help -> http://stackoverflow.com/questions/1156957/php-xml-attribute-parsing I do admit I haven't the foggiest idea what I am doing here, so I am noobing out here on how this php function is really working. I got it off php.net and am trying to implement it in my code. Without my addition it works well except it doesn't grab any attributes which I need in order for my script to work properly. Any ideas on what I am doing wrong? TIA, HTH rich Thanks rich, That uses simpleXML. I am using xml_parse_create. Any ideas for xml_parse_create? I really like the way this function puts everything into an array that I can traverse. I only need it to put the attribute values in the array for the corresponding node and I am done. *Sigh Thanks for your help, Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I came across this XML to JSON to an array some time ago. It might be something function xmlToArray($xml) { return json_decode(json_encode((array) simplexml_load_string($xml)), 1); } -- Bastien Cat, the other other white meat Actually no, I don't need the root node after all. Looks like it finally works! :) Thank you Bastien! Nice one-liner. Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML to Array
Bastien Koert On 2013-03-11, at 10:50 PM, Karl DeSaulniers wrote: > > On Mar 11, 2013, at 8:22 AM, Bastien Koert wrote: > >> On Sun, Mar 10, 2013 at 6:28 PM, Karl DeSaulniers >> wrote: >>> >>> On Mar 10, 2013, at 6:03 AM, richard gray wrote: >>> On 10/03/2013 11:47, Karl DeSaulniers wrote: > > Hi Guys, > I am hoping someone can guide me or help me fix this issue. > I have been lost in the code for some time now. > I am trying to get the attributes of an xml node. > I have this code: > [snip] this may help -> http://stackoverflow.com/questions/1156957/php-xml-attribute-parsing > > I do admit I haven't the foggiest idea what I am doing here, so I am > noobing out here on how this php function is really working. > I got it off php.net and am trying to implement it in my code. Without my > addition it works well except it doesn't grab any attributes > which I need in order for my script to work properly. > > Any ideas on what I am doing wrong? > > TIA, HTH rich >>> >>> >>> >>> Thanks rich, >>> That uses simpleXML. I am using xml_parse_create. >>> Any ideas for xml_parse_create? I really like the way this function >>> puts everything into an array that I can traverse. I only need it to put >>> the attribute values in the array for the corresponding node and I am done. >>> *Sigh >>> >>> Thanks for your help, >>> >>> Best, >>> >>> >>> Karl DeSaulniers >>> Design Drumm >>> http://designdrumm.com >>> >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >> >> I came across this XML to JSON to an array some time ago. It might be >> something >> >> function xmlToArray($xml) >> { >>return json_decode(json_encode((array) simplexml_load_string($xml)),1); >> } >> >> -- >> >> Bastien >> >> Cat, the other other white meat > > Actually no, I don't need the root node after all. > Looks like it finally works! :) > > Thank you Bastien! Nice one-liner. > > Best, > > Karl DeSaulniers > Design Drumm > Glad it works for you > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] xml to array
I've got my money on the XML spec REQUIRING an alphabetic start to tagnames, and subsequent characters can be alphanumeric... In other words, it doesn't work because <0> is not a valid XML tag. You'll have to find and read the XML spec to be 100% certain. http://info.com/XML+specification If I'm wrong, you get to file a bug report: http://bugs.php.net :-) On Fri, February 3, 2006 3:07 pm, Brian V Bonini wrote: > > > Joe > Shmoe > > foo > bar > > > <0>DNR > <1>OPT > <2>FOO > <3>BAR > <4>CWS > <5>AVS > > 72 > 96Kg > > > 0 > > etc... > > $xml_data = $xml; > $parser = xml_parser_create(); > xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); > xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); > xml_parse_into_struct($parser, $xml_data, &$values, &$tags); > xml_parser_free($parser); > > each time I print out the tags or vals it stops at the options node: > > [13] => Array > ( > [tag] => OPTIONS > [type] => open > [level] => 3 > [value] => > > ) > > [OPTIONS] => Array > ( > [0] => 13 > ) > > Something to do with the numerical node names..?? If I change them to > non-numeric vals all is good... What Am I missing?? > > -B > > > -- > > s/:-[(/]/:-)/g > > > BrianGnuPG -> KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu > == > gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC > Key Info: http://gfx-design.com/keys > Linux Registered User #339825 at http://counter.li.org > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] xml to array
On Fri, 2006-02-03 at 16:23, Richard Lynch wrote: > I've got my money on the XML spec REQUIRING an alphabetic start to > tagnames, and subsequent characters can be alphanumeric... > > In other words, it doesn't work because <0> is not a valid XML tag. Yeah, that was my instinct too... Just could not find anything to confirm it after a quick browse through the spec. Though can you find anything in the spec via a quick browse.. ;-) However, after a closer look I still can't find (at least in plain English) anything that says this is NOT OK. Though the parser does return '[xml_error] => not well-formed (invalid token)'. Good stuff -Brian -- s/:-[(/]/:-)/g BrianGnuPG -> KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu == gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC Key Info: http://gfx-design.com/keys Linux Registered User #339825 at http://counter.li.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] xml to array
Brian V Bonini wrote: On Fri, 2006-02-03 at 16:23, Richard Lynch wrote: I've got my money on the XML spec REQUIRING an alphabetic start to tagnames, and subsequent characters can be alphanumeric... In other words, it doesn't work because <0> is not a valid XML tag. Yeah, that was my instinct too... Just could not find anything to confirm it after a quick browse through the spec. Though can you find anything in the spec via a quick browse.. ;-) However, after a closer look I still can't find (at least in plain English) anything that says this is NOT OK. Though the parser does return '[xml_error] => not well-formed (invalid token)'. Good stuff -Brian Just a quick shot it the dark... http://www.w3.org/TR/REC-xml/#NT-Name Go up about a half page to this: "[Definition: A Name is a token beginning with a letter or one of a few punctuation characters, and continuing with letters, digits, hyphens, underscores, colons, or full stops, together known as name characters.] Names beginning with the string "xml", or with any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification."... From quick read maybe if you wrap the numbers in quotes that might work? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] xml to array
On Sun, 2006-02-05 at 06:32, Tod Thomas wrote: > Just a quick shot it the dark... > > http://www.w3.org/TR/REC-xml/#NT-Name > > Go up about a half page to this: > > "[Definition: A Name is a token beginning with a letter or one of a few > punctuation characters, and continuing with letters, digits, hyphens, > underscores, colons, or full stops, together known as name characters.] > Names beginning with the string "xml", or with any string which would > match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization > in this or future versions of this specification."... > > From quick read maybe if you wrap the numbers in quotes that might work? Right on... Making it work is pretty much a non-issue... I can always prepend something to the string, e.g., foo bar etc. Just was not aware if an int. was actually and invalid token... Could not recall ever seeing it used, but, could also not ever recall reading it was not OK Learn something new everyday... Thanks for finding that in the spec... -Brian -- s/:-[(/]/:-)/g BrianGnuPG -> KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu == gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC Key Info: http://gfx-design.com/keys Linux Registered User #339825 at http://counter.li.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 'XML To Array' Class
heey, i'm currently facing the same problem as you. i was thinking of using either xml_parse_into_struct or using a class i found phpxml.class at http://www.phpxml.org let me know how you did it, i'm very intrested Serge "Zeddicus Zu'l Zorandre" Vleugels -- freedom is the wizard's only choice -- On 23 Apr 2001 09:18:25 -0400, [EMAIL PROTECTED] wrote: > Hello, > > I'm new to using XML with PHP, but I think I've got it figured out for > the most part. I have created a class that reads in an XML file and > returns the data it finds to an array, but I'm running into a problem > because the array keeps coming back empty. Would you mind taking a > moment to see where I'm going wrong? > > > file.xml > === > > > /article1.html > Article 1 > > > > /article2.html > Article 2 > > > > > xml.class.php > === > > > > > class eXML > { > > > var $Parser; > > var $theArray; > var $theArrayTopElement; > var $theArrayElements; > var $theArrayPointer; > var $theArrayGetElement; > > > function eXML($_PARENT_, $_CHILDREN_) > { > > $this->Parser = xml_parser_create("ISO-8859-1"); > xml_set_object($this->Parser, &$this); > xml_set_element_handler($this- > >Parser, "Tag_Open", "Tag_Close"); > xml_set_character_data_handler($this- > >Parser, "CData"); > > $this->theArray = array(); > $this->theArrayPointer = 0; > $this->theArrayGetElement = NULL; > $this->theArrayTopElement = $_PARENT_; > $this->theArrayElements = $_CHILDREN_; > > } > > > function Free() > { > > xml_parser_free($this->Parser); > > } > > > function Parse_Array($_FILE_) > { > > $_FP_ = fopen($_FILE_, "r") or die("Cannot Open > XML Stream"); > > while ($_DATA_ = fread($_FP_, 4096)) > { > > if (!xml_parse($this->Parser, $_DATA_, > feof($_FP_))) > { > > return(FALSE); > > } > > } > > fclose($_FP_); > var_dump($this->theArray); > return($this->theArray); > > } > > > function Tag_Open($_PARSER_, $_TAG_, $_ATTR_) > { > > if ($_TAG_ == $this->theArrayTopElement) > { > > $this->theArray[$this->theArrayPointer] > = "SOMETEXT"; > // NOT SURE IF THIS IS NECESSARY > > } > > $_ELEMENTS_ = explode("::", $this- > >theArrayElements); > for ($I = 0; $I < count($_ELEMENTS_); $I++) > { > > if ($_TAG_ == $_ELEMENTS_[$I]) > { > > $this->theArrayGetElement = > $_ELEMENTS_[$I]; > > } > > } > > > } > > > function Tag_Close($_PARSER_, $_TAG_) > { > > if ($_TAG_ == $this->theArrayTopElement) > { > > $this->theArrayPointer++; > > } > > $this->theArrayGetElement = NULL; > > } > > > function CData($_PARSER_, $_CDATA_) > { > > if ($this->theArrayGetElement != NULL) > { > > array_push($this->theArray, $_CDATA_); > $this->theArray[$this->theArrayPointer] > [$this->theArrayGetElement] = $_CDATA_; > > } > > } > > } > > > ?> > > > > xml.test.php > === > > > > $XML = new eXML("ARTICLE", "URL::TITLE"); > $ARTICLES = $XML->Parse_Array("file.xml"); > print_r($ARTICLES); > > > ?> > > > What I expect to happen is this: > > $ARTICLES[0]["URL"] == "/article1.html"; > $ARTICLES[0]["TITLE"] == "Article 1"; > $ARTICLES[1]["URL"] == "/article2.html"; > $ARTICLES[1]["TITLE"] == "Article 2"; > > But the array is empty. > > Thankz in advance for your help. > Robert > > > > -- > > [ Swift eNetwork ] Matrix > http://matrix.swifte.net/ > > -- > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscrib
Re: [PHP] 'XML To Array' Class (Array Problem)
I think it's important to mention that my problem is not with XML, but with my use of arrays. I have tested the variable content that comes back with XML and the data is coming through. My problem is I am not doing something right to make the data into an array... > heey, > > i'm currently facing the same problem as you. > i was thinking of using either xml_parse_into_struct or using > a class i found phpxml.class at http://www.phpxml.org > let me know how you did it, i'm very intrested > > Serge "Zeddicus Zu'l Zorandre" Vleugels > > -- freedom is the wizard's only choice -- > > > On 23 Apr 2001 09:18:25 -0400, [EMAIL PROTECTED] wrote: > > Hello, > > > > I'm new to using XML with PHP, but I think I've got it figured out for > > the most part. I have created a class that reads in an XML file and > > returns the data it finds to an array, but I'm running into a problem > > because the array keeps coming back empty. Would you mind taking a > > moment to see where I'm going wrong? > > > > > > file.xml > > === > > > > > > /article1.html > > Article 1 > > > > > > > > /article2.html > > Article 2 > > > > > > > > > > xml.class.php > > === > > > > > > > > > > > class eXML > > { > > > > > > var $Parser; > > > > var $theArray; > > var $theArrayTopElement; > > var $theArrayElements; > > var $theArrayPointer; > > var $theArrayGetElement; > > > > > > function eXML($_PARENT_, $_CHILDREN_) > > { > > > > $this->Parser = xml_parser_create("ISO-8859- 1"); > > xml_set_object($this->Parser, &$this); > > xml_set_element_handler($this- > > >Parser, "Tag_Open", "Tag_Close"); > > xml_set_character_data_handler($this- > > >Parser, "CData"); > > > > $this->theArray = array(); > > $this->theArrayPointer = 0; > > $this->theArrayGetElement = NULL; > > $this->theArrayTopElement = $_PARENT_; > > $this->theArrayElements = $_CHILDREN_; > > > > } > > > > > > function Free() > > { > > > > xml_parser_free($this->Parser); > > > > } > > > > > > function Parse_Array($_FILE_) > > { > > > > $_FP_ = fopen($_FILE_, "r") or die("Cannot Open > > XML Stream"); > > > > while ($_DATA_ = fread($_FP_, 4096)) > > { > > > > if (!xml_parse($this->Parser, $_DATA_, > > feof($_FP_))) > > { > > > > return(FALSE); > > > > } > > > > } > > > > fclose($_FP_); > > var_dump($this->theArray); > > return($this->theArray); > > > > } > > > > > > function Tag_Open($_PARSER_, $_TAG_, $_ATTR_) > > { > > > > if ($_TAG_ == $this->theArrayTopElement) > > { > > > > $this->theArray[$this- >theArrayPointer] > > = "SOMETEXT"; > > // NOT SURE IF THIS IS NECESSARY > > > > } > > > > $_ELEMENTS_ = explode("::", $this- > > >theArrayElements); > > for ($I = 0; $I < count($_ELEMENTS_); $I++) > > { > > > > if ($_TAG_ == $_ELEMENTS_[$I]) > > { > > > > $this->theArrayGetElement = > > $_ELEMENTS_[$I]; > > > > } > > > > } > > > > > > } > > > > > > function Tag_Close($_PARSER_, $_TAG_) > > { > > > > if ($_TAG_ == $this->theArrayTopElement) > > { > > > > $this->theArrayPointer++; > > > > } > > > > $this->theArrayGetElement = NULL; > > > > } > > > > > > function CData($_PARSER_, $_CDATA_) > > { > > > > if ($this->theArrayGetElement != NULL) > > { > > > > array_push($this->theArray, $_CDATA_); > > $this->theArray[$this- >theArrayPointer] > > [$this->theArrayGetElement] = $_CDATA_; > > > > } > > > > } > > > > } > > > > > > ?> > > > > > > > > xml.test.php > > =