RE: [PHP] XML: Similiar Multiple Tags With Different Data
I hope I didn't sound impolite, I really didn't mean to offend you, because if it weren't for your tutorial I would probably still be trying to figure out how to parse attributes and get XML Content into variables. Anyway, the performance and efficiency doesn't really interest me at this point. I just want to get the thing working before I work on improving it. What I really want to do is build up to a full time XML Database application. I know a flat file XML DB won't be as fast as mySQL, but the entries can be edited with any text editor, and ported to any platform, and it will be fairly easy to do. I just have to get the hang of XML Parsing and I will be half way there. Anyway, you asked What's the point of doing the if == 'LIST_ITEM' check in the character handler rather than the end handler?, well the point is that if it is LIST_ITEM I want to the content in a variable. As far as I know this cannot be done in the end handler. Second of all the array_push is there for a reason I am not even sure about, but when I try to remove it the code doesn't work. I will experiment later with alternatives, but for now my main concern is what I previously mentioned: Getting the different values from the same XML tag into an array. PS: Please be polite. Don't top post and only include immediately relevant portions from prior emails. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML: Similiar Multiple Tags With Different Data
On Wed, May 15, 2002 at 07:49:58PM +0200, Sebastian A. wrote: performance and efficiency doesn't really interest me at this point. I just want to get the thing working before I work on improving it. But your haste is making waste. Even funnier, in your haste, you're making more work for yourself. Anyway, you asked What's the point of doing the if == 'LIST_ITEM' check in the character handler rather than the end handler?, well the point is that if it is LIST_ITEM I want to the content in a variable. As far as I know this cannot be done in the end handler. That's why I temporarily store the content in the $CData array. Then, when I get to the end handler, I extract the data from the $CData array, and do what is necessary with it. Second of all the array_push is there for a reason I am not even sure about, but when I try to remove it the code doesn't work. But your code isn't working with it either. It's adds a whole series of unnecessary steps. Again, look at the tutorial, http://www.analysisandsolutions.com/code/phpxml.htm, and modify ONLY what you need to. In your case, the only thing you need to change is adding a special case for 'LIST_ITEM' to the switch in the end handler function. THAT'S where you'll stick that stuff into the $p object you were trying to do in the content handler. Oh, of course, drop the case in that switch statement that don't apply to your DTD, but that goes without saying. Good luck, --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] XML: Similiar Multiple Tags With Different Data
Ok I see where you're going with this. Thanks a lot. I will be sure to improvise my code. -Original Message- From: Analysis Solutions [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 15, 2002 8:10 PM To: PHP List Subject: Re: [PHP] XML: Similiar Multiple Tags With Different Data On Wed, May 15, 2002 at 07:49:58PM +0200, Sebastian A. wrote: performance and efficiency doesn't really interest me at this point. I just want to get the thing working before I work on improving it. But your haste is making waste. Even funnier, in your haste, you're making more work for yourself. Anyway, you asked What's the point of doing the if == 'LIST_ITEM' check in the character handler rather than the end handler?, well the point is that if it is LIST_ITEM I want to the content in a variable. As far as I know this cannot be done in the end handler. That's why I temporarily store the content in the $CData array. Then, when I get to the end handler, I extract the data from the $CData array, and do what is necessary with it. Second of all the array_push is there for a reason I am not even sure about, but when I try to remove it the code doesn't work. But your code isn't working with it either. It's adds a whole series of unnecessary steps. Again, look at the tutorial, http://www.analysisandsolutions.com/code/phpxml.htm, and modify ONLY what you need to. In your case, the only thing you need to change is adding a special case for 'LIST_ITEM' to the switch in the end handler function. THAT'S where you'll stick that stuff into the $p object you were trying to do in the content handler. Oh, of course, drop the case in that switch statement that don't apply to your DTD, but that goes without saying. Good luck, --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] XML: Similiar Multiple Tags With Different Data
Ok well that function is the character_data_handler function. Here is the Start Element function: function startElement($parser, $name, $attrs='') { global $tag, $Data, $p; array_push( $tag, $name ); while ( list($Key,$Val) = each($attrs) ) { $p-attr_data[$name:$Key] = trim($Val); } } Here is the end element function: function endElement($parser, $name) { global $tag; } And I just wanted to mention that a lot of that code is from your tutorial (Anlysis and Solutions). I was just experimenting with it, trying to get different things to work. You should know pretty well what everything does. Another thing is that, I think this problem might have something to do with the array_push function in the Start Element function, however I am not sure. -Original Message- From: Analysis Solutions [mailto:[EMAIL PROTECTED]] Sent: Monday, May 13, 2002 10:04 PM To: PHP List Subject: Re: [PHP] XML: Similiar Multiple Tags With Different Data On Mon, May 13, 2002 at 05:49:04PM +0200, Sebastian A. wrote: function elementContent($parser, $data, $attrs='') { global $tag, $p; $ti = sizeof( $tag ) - 1; if ( $tag[$ti] == 'LIST_ITEM' ) { $p-ART_ID[] = $data; } } You're not posting enough of your code for us to understand how you got here. For example, which parser function are we looking at here? I'm guessing it's the character_data_handler. But, it's not supposed to have an $attrs argument. [OY! I just cought a bug in my online tutorial... Had an $Attr argument for the end handler. Fixed it.] Also, where's the $tag array coming from? Why's it an array? Let alone, why are you trying to process stuff in the content handler when it's more effective to handle it in the end handler? --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML: Similiar Multiple Tags With Different Data
Yo, Sebastian: On Tue, May 14, 2002 at 07:26:30PM +0200, Sebastian A. wrote: function startElement($parser, $name, $attrs='') { global $tag, $Data, $p; array_push( $tag, $name ); while ( list($Key,$Val) = each($attrs) ) { $p-attr_data[$name:$Key] = trim($Val); } } [cut and pasted from earlier email... --dc] function elementContent($parser, $data, $attrs='') { global $tag, $p; $ti = sizeof( $tag ) - 1; if ( $tag[$ti] == 'LIST_ITEM' ) { $p-ART_ID[] = $data; } } function endElement($parser, $name) { global $tag; } And I just wanted to mention that a lot of that code is from your tutorial Not really. You're doing everything differently. It's a lot less efficient. More importantly, it's not working. For instance... What's the point of doing the if == 'LIST_ITEM' check in the character handler rather than the end handler? What's the point of the array push when the data available therefrom is already available in the $name variable? --Dan PS: Please be polite. Don't top post and only include immediately relevant portions from prior emails. -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] XML: Similiar Multiple Tags With Different Data
I tried your suggestion already but It doesn't seem to work. I still can get it to be assigned to different parts of the array. Do you have any other suggestions? -Original Message- From: Kjartan Mannes [mailto:[EMAIL PROTECTED]] Sent: Sunday, May 12, 2002 11:10 PM To: Sebastian A. Cc: PHP General List (PHP.NET) Subject: Re: [PHP] XML: Similiar Multiple Tags With Different Data Sunday, May 12, 2002, 6:39:31 PM, Sebastian A. wrote: Hello I have recently been trying to parse an XML document that has different content in the same tags. Here is an example: LIST_ITEM1/LIST_ITEM LIST_ITEM2/LIST_ITEM LIST_ITEM3/LIST_ITEM ... I am trying to get the content from LIST_ITEM into an array. I want the content of the first LIST_ITEM to go into $p-ART_ID[0] and the next to go into $p-ART_ID[1] and so on. Here is what my Element Content Function looks like: Without the rest of the code I would suspect this to work: function elementContent($parser, $data, $attrs='') { global $tag, $p; $ti = sizeof( $tag ) - 1; if ( $tag[$ti] == 'LIST_ITEM' ) { $p-ART_ID[] = $data; } } Basically when you are assigning content to a new part of the array you don't use .= but just = -- Kjartan [EMAIL PROTECTED] (http://natrak.net/) :: A program is a spell cast over a computer, turning input into error messages. :: Drupal (www.drupal.org) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML: Similiar Multiple Tags With Different Data
On Mon, May 13, 2002 at 05:49:04PM +0200, Sebastian A. wrote: function elementContent($parser, $data, $attrs='') { global $tag, $p; $ti = sizeof( $tag ) - 1; if ( $tag[$ti] == 'LIST_ITEM' ) { $p-ART_ID[] = $data; } } You're not posting enough of your code for us to understand how you got here. For example, which parser function are we looking at here? I'm guessing it's the character_data_handler. But, it's not supposed to have an $attrs argument. [OY! I just cought a bug in my online tutorial... Had an $Attr argument for the end handler. Fixed it.] Also, where's the $tag array coming from? Why's it an array? Let alone, why are you trying to process stuff in the content handler when it's more effective to handle it in the end handler? --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] XML: Similiar Multiple Tags With Different Data
Hello I have recently been trying to parse an XML document that has different content in the same tags. Here is an example: LIST_ITEM1/LIST_ITEM LIST_ITEM2/LIST_ITEM LIST_ITEM3/LIST_ITEM ... I am trying to get the content from LIST_ITEM into an array. I want the content of the first LIST_ITEM to go into $p-ART_ID[0] and the next to go into $p-ART_ID[1] and so on. Here is what my Element Content Function looks like: - function elementContent($parser, $data, $attrs='') { global $tag, $data, $test; global $p; $ti = sizeof( $tag ) - 1; if ( $tag[$ti] == 'LIST_ITEM' ) { $p-ART_ID[] .= $data; } } When I type in echo $p-ART_ID[0] I should get 1 however I get 1 2 3. For some reason all the content goes only into one section of the array. Does anyone know how I can fix this? Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML: Similiar Multiple Tags With Different Data
Sunday, May 12, 2002, 6:39:31 PM, Sebastian A. wrote: Hello I have recently been trying to parse an XML document that has different content in the same tags. Here is an example: LIST_ITEM1/LIST_ITEM LIST_ITEM2/LIST_ITEM LIST_ITEM3/LIST_ITEM ... I am trying to get the content from LIST_ITEM into an array. I want the content of the first LIST_ITEM to go into $p-ART_ID[0] and the next to go into $p-ART_ID[1] and so on. Here is what my Element Content Function looks like: Without the rest of the code I would suspect this to work: function elementContent($parser, $data, $attrs='') { global $tag, $p; $ti = sizeof( $tag ) - 1; if ( $tag[$ti] == 'LIST_ITEM' ) { $p-ART_ID[] = $data; } } Basically when you are assigning content to a new part of the array you don't use .= but just = -- Kjartan [EMAIL PROTECTED] (http://natrak.net/) :: A program is a spell cast over a computer, turning input into error messages. :: Drupal (www.drupal.org) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php