473,326 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

getting the right XML tag in the parse.

I'm trying to parse an XML formatted post reply, and I can't figure
out how to get the value of the right tag.
The XML is formatted like this:

<A>
<foo>val1</foo>
</A>
<B>
<foo>val2</foo>
</B>
<BAR>
val3
</BAR>

I need the value of A's "foo", not B's "foo". But from what I can find
I can only get the value of the lowest nested tag in a nest. i.e.:
"foo" or "BAR". Not specifically A or B's "foo".
Below is the script I'm using. In this case "TOTALCHARGES" is the
"foo" I'm looking for, but I need it to specifically get A's and not
B's.
If someone can point me to where I can find out how, I'd appreciate
it!
-Liam

//Defines startElement function
function startElement($xml_parser, $element_name, $element_attrs) {
global $printout, $tag, $output1;

switch($element_name) {
case "TOTALCHARGES":
$printout = true;
$tag = "TOTALCHARGES";
break;
}
}

//Defines endElement function
function endElement($xml_parser, $element_name) {
global $printout, $tag, $output1;

switch($element_name) {
case "TOTALCHARGES":
$printout = false;
$tag = "";
break;
}
}

//Defines characterData function
function characterData($xml_parser, $fp) {
global $printout, $tag, $output1;

if (($tag=="TOTALCHARGES") && ($printout==true)) {
$output1 = $fp;
//echo $output;
}
return $output1;
}
Jul 18 '08 #1
16 1587
..oO(ne**@celticbear.com)
>I'm trying to parse an XML formatted post reply, and I can't figure
out how to get the value of the right tag.
The XML is formatted like this:

<A>
<foo>val1</foo>
</A>
<B>
<foo>val2</foo>
</B>
<BAR>
val3
</BAR>
If this is the entire document, then it's not well-formed XML, because
there's no root element.
>I need the value of A's "foo", not B's "foo". But from what I can find
I can only get the value of the lowest nested tag in a nest. i.e.:
"foo" or "BAR". Not specifically A or B's "foo".
Of course you can access every element and every attribute in the tree.
Just use the right tools.
>Below is the script I'm using. In this case "TOTALCHARGES" is the
"foo" I'm looking for, but I need it to specifically get A's and not
B's.
If someone can point me to where I can find out how, I'd appreciate
it!
[...]
You don't have to write your own parser. Use the SimpleXML extension
with some XPath expressions to get all the nodes you want.

Micha
Jul 18 '08 #2
On Jul 18, 10:51*am, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
I'm trying to parse an XML formatted post reply, and I can't figure
out how to get the value of the right tag.
The XML is formatted like this:
<A>
* <foo>val1</foo>
</A>
<B>
* <foo>val2</foo>
</B>
<BAR>
* val3
</BAR>

If this is the entire document, then it's not well-formed XML, because
there's no root element.
LOL of course that's not the whole document, not the document at all.
It's an example specifically the nesting and tag labeling that I'm
talking about--for the sake of example.
I need the value of A's "foo", not B's "foo". But from what I can find
I can only get the value of the lowest nested tag in a nest. i.e.:
"foo" or "BAR". Not specifically A or B's "foo".

Of course you can access every element and every attribute in the tree.
Just use the right tools.
I knew it was possible...I was asking for advice HOW. WHAT are the
right tools?
Below is the script I'm using. In this case "TOTALCHARGES" is the
"foo" I'm looking for, but I need it to specifically get A's and not
B's.
If someone can point me to where I can find out how, I'd appreciate
it!
[...]

You don't have to write your own parser. Use the SimpleXML extension
with some XPath expressions to get all the nodes you want.
In my opinion, writing several lines of script in standard PHP is a
LOT easier than installing an extension (and learning how to install
an extension as I've never done that before.)
IF that's the ONLY way to do what I need to do, then so be it. I'll
figure out how to install SimpleXML and how to use XPath.
But if there's a way to do it by simply modifying the regular PHP
getElements and characterData, etc, that's the best way for me to go.
Jul 18 '08 #3
..oO(ne**@celticbear.com)
>On Jul 18, 10:51*am, Michael Fesser <neti...@gmx.dewrote:
>I need the value of A's "foo", not B's "foo". But from what I can find
I can only get the value of the lowest nested tag in a nest. i.e.:
"foo" or "BAR". Not specifically A or B's "foo".

Of course you can access every element and every attribute in the tree.
Just use the right tools.

I knew it was possible...I was asking for advice HOW. WHAT are the
right tools?
>Below is the script I'm using. In this case "TOTALCHARGES" is the
"foo" I'm looking for, but I need it to specifically get A's and not
B's.
If someone can point me to where I can find out how, I'd appreciate
it!
[...]

You don't have to write your own parser. Use the SimpleXML extension
with some XPath expressions to get all the nodes you want.

In my opinion, writing several lines of script in standard PHP is a
LOT easier than installing an extension (and learning how to install
an extension as I've never done that before.)
Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default in
every recent PHP. We are talking about PHP 5, right?
>IF that's the ONLY way to do what I need to do, then so be it. I'll
figure out how to install SimpleXML and how to use XPath.
Check phpinfo() to see if SimpleXML is already there (it should be).
Then check the manual for some examples on how to use it with XPath
syntax to fetch arbitrary elements from an XML tree. Can't get any
easier.

Micha
Jul 18 '08 #4
On Jul 18, 2:29*pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
On Jul 18, 10:51*am, Michael Fesser <neti...@gmx.dewrote:
I need the value of A's "foo", not B's "foo". But from what I can find
I can only get the value of the lowest nested tag in a nest. i.e.:
"foo" or "BAR". Not specifically A or B's "foo".
Of course you can access every element and every attribute in the tree..
Just use the right tools.
I knew it was possible...I was asking for advice HOW. WHAT are the
right tools?
Below is the script I'm using. In this case "TOTALCHARGES" is the
"foo" I'm looking for, but I need it to specifically get A's and not
B's.
If someone can point me to where I can find out how, I'd appreciate
it!
[...]
You don't have to write your own parser. Use the SimpleXML extension
with some XPath expressions to get all the nodes you want.
In my opinion, writing several lines of script in standard PHP is a
LOT easier than installing an extension (and learning how to install
an extension as I've never done that before.)

Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default in
every recent PHP. We are talking about PHP 5, right?
IF that's the ONLY way to do what I need to do, then so be it. I'll
figure out how to install SimpleXML and how to use XPath.

Check phpinfo() to see if SimpleXML is already there (it should be).
Then check the manual for some examples on how to use it with XPath
syntax to fetch arbitrary elements from an XML tree. Can't get any
easier.
Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
yet...but I don't recall. One of the other developers are saying a
hundred pages will have to be rewritten before we can convert
otherwise it will completely mess up our e-commerce site.
So no, SimpleXML is not found in my phpinfo(). =/
Jul 18 '08 #5
On Jul 18, 2:47*pm, "n...@celticbear.com" <n...@celticbear.comwrote:
On Jul 18, 2:29*pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
>On Jul 18, 10:51*am, Michael Fesser <neti...@gmx.dewrote:
>I need the value of A's "foo", not B's "foo". But from what I can find
>I can only get the value of the lowest nested tag in a nest. i.e.:
>"foo" or "BAR". Not specifically A or B's "foo".
>Of course you can access every element and every attribute in the tree.
>Just use the right tools.
>I knew it was possible...I was asking for advice HOW. WHAT are the
>right tools?
>Below is the script I'm using. In this case "TOTALCHARGES" is the
>"foo" I'm looking for, but I need it to specifically get A's and not
>B's.
>If someone can point me to where I can find out how, I'd appreciate
>it!
>[...]
>You don't have to write your own parser. Use the SimpleXML extension
>with some XPath expressions to get all the nodes you want.
>In my opinion, writing several lines of script in standard PHP is a
>LOT easier than installing an extension (and learning how to install
>an extension as I've never done that before.)
Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default in
every recent PHP. We are talking about PHP 5, right?
>IF that's the ONLY way to do what I need to do, then so be it. I'll
>figure out how to install SimpleXML and how to use XPath.
Check phpinfo() to see if SimpleXML is already there (it should be).
Then check the manual for some examples on how to use it with XPath
syntax to fetch arbitrary elements from an XML tree. Can't get any
easier.

Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
yet...but I don't recall. One of the other developers are saying a
hundred pages will have to be rewritten before we can convert
otherwise it will completely mess up our e-commerce site.
So no, SimpleXML is not found in my phpinfo(). =/
But it does have domxml, if that means anything:

domxml
DOM/XML enabled
DOM/XML API Version 20020815
libxml Version 20616
HTML Support enabled
XPath Support enabled
XPointer Support enabled
DOM/XSLT enabled
libxslt Version 1.1.11
libxslt compiled against libxml Version 2.6.16
DOM/EXSLT enabled
libexslt Version 1.1.11
Jul 18 '08 #6
ne**@celticbear.com wrote:
On Jul 18, 2:47 pm, "n...@celticbear.com" <n...@celticbear.comwrote:
>On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
>On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.dewrote:
>I need the value of A's "foo", not B's "foo". But from what I
can find I can only get the value of the lowest nested tag in
a nest. i.e.: "foo" or "BAR". Not specifically A or B's "foo".
>Of course you can access every element and every attribute in
the tree. Just use the right tools.
>I knew it was possible...I was asking for advice HOW. WHAT are the
right tools?
>Below is the script I'm using. In this case "TOTALCHARGES" is
the "foo" I'm looking for, but I need it to specifically get
A's and not B's.
If someone can point me to where I can find out how, I'd
appreciate it!
[...]
>You don't have to write your own parser. Use the SimpleXML
extension with some XPath expressions to get all the nodes you
want.
>In my opinion, writing several lines of script in standard PHP is
a LOT easier than installing an extension (and learning how to
install an extension as I've never done that before.)
Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default
in every recent PHP. We are talking about PHP 5, right?
>IF that's the ONLY way to do what I need to do, then so be it.
I'll figure out how to install SimpleXML and how to use XPath.
Check phpinfo() to see if SimpleXML is already there (it should
be). Then check the manual for some examples on how to use it with
XPath syntax to fetch arbitrary elements from an XML tree. Can't
get any easier.

Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
yet...but I don't recall. One of the other developers are saying a
hundred pages will have to be rewritten before we can convert
otherwise it will completely mess up our e-commerce site.
So no, SimpleXML is not found in my phpinfo(). =/
How about: http://www.phpclasses.org/browse/file/22596.html
no extensions to load.
Jul 18 '08 #7
On Jul 18, 2:47*pm, "n...@celticbear.com" <n...@celticbear.comwrote:
On Jul 18, 2:29*pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
>On Jul 18, 10:51*am, Michael Fesser <neti...@gmx.dewrote:
>I need the value of A's "foo", not B's "foo". But from what I can find
>I can only get the value of the lowest nested tag in a nest. i.e.:
>"foo" or "BAR". Not specifically A or B's "foo".
>Of course you can access every element and every attribute in the tree.
>Just use the right tools.
>I knew it was possible...I was asking for advice HOW. WHAT are the
>right tools?
>Below is the script I'm using. In this case "TOTALCHARGES" is the
>"foo" I'm looking for, but I need it to specifically get A's and not
>B's.
>If someone can point me to where I can find out how, I'd appreciate
>it!
>[...]
>You don't have to write your own parser. Use the SimpleXML extension
>with some XPath expressions to get all the nodes you want.
>In my opinion, writing several lines of script in standard PHP is a
>LOT easier than installing an extension (and learning how to install
>an extension as I've never done that before.)
Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default in
every recent PHP. We are talking about PHP 5, right?
>IF that's the ONLY way to do what I need to do, then so be it. I'll
>figure out how to install SimpleXML and how to use XPath.
Check phpinfo() to see if SimpleXML is already there (it should be).
Then check the manual for some examples on how to use it with XPath
syntax to fetch arbitrary elements from an XML tree. Can't get any
easier.

Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
yet...but I don't recall. One of the other developers are saying a
hundred pages will have to be rewritten before we can convert
otherwise it will completely mess up our e-commerce site.
So no, SimpleXML is not found in my phpinfo(). =/
If I remember correctly, it sometimes is possible to have 2 versions
of php on a server. In your case that would mean keeping your current
version of 4 as primary for the extension .php and using the
extension .php5 for the new 5 version. If that can be done and you can
find someone to do it for your server, then you perhaps could keep all
happy. I recently moved my two domains and a subdomain from an old
server that supported php 4 only to a new server that supports php 5
only. There were only a very few minor problems with any of my pages,
and no problems with the php upgrade. Of course some others may have
written code, some of which even predates php4, that causes problems
on an upgrade to php5.
Jul 18 '08 #8
On Jul 18, 3:47*pm, cwdjrxyz <spamtr...@cwdjr.infowrote:
On Jul 18, 2:47*pm, "n...@celticbear.com" <n...@celticbear.comwrote:
On Jul 18, 2:29*pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
On Jul 18, 10:51*am, Michael Fesser <neti...@gmx.dewrote:
I need the value of A's "foo", not B's "foo". But from what I canfind
I can only get the value of the lowest nested tag in a nest. i.e.:
"foo" or "BAR". Not specifically A or B's "foo".
Of course you can access every element and every attribute in the tree.
Just use the right tools.
I knew it was possible...I was asking for advice HOW. WHAT are the
right tools?
Below is the script I'm using. In this case "TOTALCHARGES" is the
"foo" I'm looking for, but I need it to specifically get A's and not
B's.
If someone can point me to where I can find out how, I'd appreciate
it!
[...]
You don't have to write your own parser. Use the SimpleXML extension
with some XPath expressions to get all the nodes you want.
In my opinion, writing several lines of script in standard PHP is a
LOT easier than installing an extension (and learning how to install
an extension as I've never done that before.)
Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default in
every recent PHP. We are talking about PHP 5, right?
IF that's the ONLY way to do what I need to do, then so be it. I'll
figure out how to install SimpleXML and how to use XPath.
Check phpinfo() to see if SimpleXML is already there (it should be).
Then check the manual for some examples on how to use it with XPath
syntax to fetch arbitrary elements from an XML tree. Can't get any
easier.
Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
yet...but I don't recall. One of the other developers are saying a
hundred pages will have to be rewritten before we can convert
otherwise it will completely mess up our e-commerce site.
So no, SimpleXML is not found in my phpinfo(). =/

If I remember correctly, it sometimes is possible to have 2 versions
of php on a server. In your case that would mean keeping your current
version of 4 as primary for the extension .php and using the
extension .php5 for the new 5 version. If that can be done and you can
find someone to do it for your server, then you perhaps could keep all
happy. I recently moved my two domains and a subdomain from an old
server that supported php 4 only to a new server that supports php 5
only. There were only a very few minor problems with any of my pages,
and no problems with the php upgrade. Of course some others may have
written code, some of which even predates php4, that causes problems
on an upgrade to php5.
Hmm, cool. Thanks for the reply! I'll check into that.
-Liam
Jul 18 '08 #9
ne**@celticbear.com wrote:
On Jul 18, 3:47 pm, cwdjrxyz <spamtr...@cwdjr.infowrote:
>On Jul 18, 2:47 pm, "n...@celticbear.com" <n...@celticbear.comwrote:
>>On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.dewrote:
>>I need the value of A's "foo", not B's "foo". But from what I can find
>>I can only get the value of the lowest nested tag in a nest. i.e.:
>>"foo" or "BAR". Not specifically A or B's "foo".
>Of course you can access every element and every attribute in the tree.
>Just use the right tools.
I knew it was possible...I was asking for advice HOW. WHAT are the
right tools?
>>Below is the script I'm using. In this case "TOTALCHARGES" is the
>>"foo" I'm looking for, but I need it to specifically get A's and not
>>B's.
>>If someone can point me to where I can find out how, I'd appreciate
>>it!
>>[...]
>You don't have to write your own parser. Use the SimpleXML extension
>with some XPath expressions to get all the nodes you want.
In my opinion, writing several lines of script in standard PHP is a
LOT easier than installing an extension (and learning how to install
an extension as I've never done that before.)
Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default in
every recent PHP. We are talking about PHP 5, right?
IF that's the ONLY way to do what I need to do, then so be it. I'll
figure out how to install SimpleXML and how to use XPath.
Check phpinfo() to see if SimpleXML is already there (it should be).
Then check the manual for some examples on how to use it with XPath
syntax to fetch arbitrary elements from an XML tree. Can't get any
easier.
Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
yet...but I don't recall. One of the other developers are saying a
hundred pages will have to be rewritten before we can convert
otherwise it will completely mess up our e-commerce site.
So no, SimpleXML is not found in my phpinfo(). =/
If I remember correctly, it sometimes is possible to have 2 versions
of php on a server. In your case that would mean keeping your current
version of 4 as primary for the extension .php and using the
extension .php5 for the new 5 version. If that can be done and you can
find someone to do it for your server, then you perhaps could keep all
happy. I recently moved my two domains and a subdomain from an old
server that supported php 4 only to a new server that supports php 5
only. There were only a very few minor problems with any of my pages,
and no problems with the php upgrade. Of course some others may have
written code, some of which even predates php4, that causes problems
on an upgrade to php5.

Hmm, cool. Thanks for the reply! I'll check into that.
-Liam
Yes, you need to get on PHP5 ASAP. PHP4 is at end of life - there will
not be any patches any more for it - not even security patches. So
you're running a completely unsupported product.

Not to say there hasn't been warning - about 2 years worth.

But virtually everything I've ever had on PHP4 runs fine on PHP5. If
your have a lot of pages which don't work right, chances are someone was
doing something rather flaky in the first place. There just aren't THAT
many incompatibilities between the two.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jul 19 '08 #10
On Jul 18, 7:45*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
n...@celticbear.com wrote:
On Jul 18, 3:47 pm, cwdjrxyz <spamtr...@cwdjr.infowrote:
On Jul 18, 2:47 pm, "n...@celticbear.com" <n...@celticbear.comwrote:
>On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.dewrote:
>I need the value of A's "foo", not B's "foo". But from what I canfind
>I can only get the value of the lowest nested tag in a nest. i.e.:
>"foo" or "BAR". Not specifically A or B's "foo".
Of course you can access every element and every attribute in the tree.
Just use the right tools.
I knew it was possible...I was asking for advice HOW. WHAT are the
right tools?
>Below is the script I'm using. In this case "TOTALCHARGES" is the
>"foo" I'm looking for, but I need it to specifically get A's and not
>B's.
>If someone can point me to where I can find out how, I'd appreciate
>it!
>[...]
You don't have to write your own parser. Use the SimpleXML extension
with some XPath expressions to get all the nodes you want.
In my opinion, writing several lines of script in standard PHP is a
LOT easier than installing an extension (and learning how to install
an extension as I've never done that before.)
Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default in
every recent PHP. We are talking about PHP 5, right?
IF that's the ONLY way to do what I need to do, then so be it. I'll
figure out how to install SimpleXML and how to use XPath.
Check phpinfo() to see if SimpleXML is already there (it should be).
Then check the manual for some examples on how to use it with XPath
syntax to fetch arbitrary elements from an XML tree. Can't get any
easier.
Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
yet...but I don't recall. One of the other developers are saying a
hundred pages will have to be rewritten before we can convert
otherwise it will completely mess up our e-commerce site.
So no, SimpleXML is not found in my phpinfo(). =/
If I remember correctly, it sometimes is possible to have 2 versions
of php on a server. In your case that would mean keeping your current
version of 4 as primary for the extension .php and using the
extension .php5 for the new 5 version. If that can be done and you can
find someone to do it for your server, then you perhaps could keep all
happy. I recently moved my two domains and a subdomain from an old
server that supported php 4 only to a new server that supports php 5
only. There were only a very few minor problems with any of my pages,
and no problems with the php upgrade. Of course some others may have
written code, some of which even predates php4, that causes problems
on an upgrade to php5.
Hmm, cool. Thanks for the reply! I'll check into that.
-Liam

Yes, you need to get on PHP5 ASAP. *PHP4 is at end of life - there will
not be any patches any more for it - not even security patches. *So
you're running a completely unsupported product.

Not to say there hasn't been warning - about 2 years worth.

But virtually everything I've ever had on PHP4 runs fine on PHP5. *If
your have a lot of pages which don't work right, chances are someone was
doing something rather flaky in the first place. *There just aren't THAT
many incompatibilities between the two.
Yeah, someone was doing something flaky in the first place. We have
"layout" scripts written back in the time of PHP 3 that utilize
ImageMagick and PDFLib, and something about the way they're written
messes up under PHP5. There's a LOT of problems with our site! Lots.
I've tried to correct as much as I can the last couple of years but
there's still so much that requires rewriting.

In the meantime, I have to add features that have to get working ASAP
before I can continue trying to overhaul.
Jul 21 '08 #11
On Jul 18, 3:12*pm, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
n...@celticbear.com wrote:
On Jul 18, 2:47 pm, "n...@celticbear.com" <n...@celticbear.comwrote:
On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
>On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.dewrote:
>I need the value of A's "foo", not B's "foo". But from what I
>can find I can only get the value of the lowest nested tag in
>a nest. i.e.: "foo" or "BAR". Not specifically A or B's "foo".
>Of course you can access every element and every attribute in
>the tree. Just use the right tools.
>I knew it was possible...I was asking for advice HOW. WHAT are the
>right tools?
>Below is the script I'm using. In this case "TOTALCHARGES" is
>the "foo" I'm looking for, but I need it to specifically get
>A's and not B's.
>If someone can point me to where I can find out how, I'd
>appreciate it!
>[...]
>You don't have to write your own parser. Use the SimpleXML
>extension with some XPath expressions to get all the nodes you
>want.
>In my opinion, writing several lines of script in standard PHP is
>a LOT easier than installing an extension (and learning how to
>install an extension as I've never done that before.)
Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default
in every recent PHP. We are talking about PHP 5, right?
>IF that's the ONLY way to do what I need to do, then so be it.
>I'll figure out how to install SimpleXML and how to use XPath.
Check phpinfo() to see if SimpleXML is already there (it should
be). Then check the manual for some examples on how to use it with
XPath syntax to fetch arbitrary elements from an XML tree. Can't
get any easier.
Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
yet...but I don't recall. One of the other developers are saying a
hundred pages will have to be rewritten before we can convert
otherwise it will completely mess up our e-commerce site.
So no, SimpleXML is not found in my phpinfo(). =/

How about:http://www.phpclasses.org/browse/file/22596.html
no extensions to load.
OK, this is ridiculous...how does one install a class?
By the looks of it, this is just a PHP script that maybe I just need
to include() at the top of other pages, but I'm not sure.
The phpclasses site has no help on what to DO with these class pages,
and googling isn't coming up with anything.
This is probably a very stupid question, no, I'm certain it is, but
what do I DO with this simplexlm.class.php?
Thanks
Jul 21 '08 #12
..oO(ne**@celticbear.com)
>On Jul 18, 3:12*pm, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
>>
How about:http://www.phpclasses.org/browse/file/22596.html
no extensions to load.

OK, this is ridiculous...how does one install a class?
By the looks of it, this is just a PHP script that maybe I just need
to include() at the top of other pages, but I'm not sure.
The phpclasses site has no help on what to DO with these class pages,
and googling isn't coming up with anything.
This is probably a very stupid question, no, I'm certain it is, but
what do I DO with this simplexlm.class.php?
You've already answered it: You just 'include' or 'require' it.

Micha
Jul 21 '08 #13
ne**@celticbear.com wrote:
On Jul 18, 3:12 pm, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
>n...@celticbear.com wrote:
>>On Jul 18, 2:47 pm, "n...@celticbear.com" <n...@celticbear.comwrote:
On Jul 18, 2:29 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
>On Jul 18, 10:51 am, Michael Fesser <neti...@gmx.dewrote:
>>>I need the value of A's "foo", not B's "foo". But from what I
>>>can find I can only get the value of the lowest nested tag in
>>>a nest. i.e.: "foo" or "BAR". Not specifically A or B's "foo".
>>Of course you can access every element and every attribute in
>>the tree. Just use the right tools.
>I knew it was possible...I was asking for advice HOW. WHAT are the
>right tools?
>>>Below is the script I'm using. In this case "TOTALCHARGES" is
>>>the "foo" I'm looking for, but I need it to specifically get
>>>A's and not B's.
>>>If someone can point me to where I can find out how, I'd
>>>appreciate it!
>>>[...]
>>You don't have to write your own parser. Use the SimpleXML
>>extension with some XPath expressions to get all the nodes you
>>want.
>In my opinion, writing several lines of script in standard PHP is
>a LOT easier than installing an extension (and learning how to
>install an extension as I've never done that before.)
Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default
in every recent PHP. We are talking about PHP 5, right?
>IF that's the ONLY way to do what I need to do, then so be it.
>I'll figure out how to install SimpleXML and how to use XPath.
Check phpinfo() to see if SimpleXML is already there (it should
be). Then check the manual for some examples on how to use it with
XPath syntax to fetch arbitrary elements from an XML tree. Can't
get any easier.
Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
yet...but I don't recall. One of the other developers are saying a
hundred pages will have to be rewritten before we can convert
otherwise it will completely mess up our e-commerce site.
So no, SimpleXML is not found in my phpinfo(). =/
How about:http://www.phpclasses.org/browse/file/22596.html
no extensions to load.

OK, this is ridiculous...how does one install a class?
By the looks of it, this is just a PHP script that maybe I just need
to include() at the top of other pages, but I'm not sure.
Correct. You then instantiate an object of that class with the "new"
statement.

require_once 'somewhere/foo.php';
$fooObj = new foo();
$thisOne = $foo->a_foo_method();
The phpclasses site has no help on what to DO with these class pages,
and googling isn't coming up with anything.
This is probably a very stupid question, no, I'm certain it is, but
what do I DO with this simplexlm.class.php?
Thanks
Jul 21 '08 #14
On Jul 18, 10:16*am, "n...@celticbear.com" <n...@celticbear.com>
wrote:
I'm trying to parse an XML formatted post reply, and I can't figure
out how to get the value of the right tag.
The XML is formatted like this:

<A>
* *<foo>val1</foo>
</A>
<B>
* *<foo>val2</foo>
</B>
<BAR>
* *val3
</BAR>

I need the value of A's "foo", not B's "foo". But from what I can find
I can only get the value of the lowest nested tag in a nest. i.e.:
"foo" or "BAR". Not specifically A or B's "foo".
Below is the script I'm using. In this case "TOTALCHARGES" is the
"foo" I'm looking for, but I need it to specifically get A's and not
B's.
If someone can point me to where I can find out how, I'd appreciate
it!
-Liam

//Defines startElement function
function startElement($xml_parser, $element_name, $element_attrs) {
* * * * global $printout, $tag, $output1;

* * * * switch($element_name) {
* * * * * * * * case "TOTALCHARGES":
* * * * * * * * * * * * $printout = true;
* * * * * * * * * * * * $tag = "TOTALCHARGES";
* * * * * * * * * * * * break;
* * * * }

}

//Defines endElement function
function endElement($xml_parser, $element_name) {
* * * * global $printout, $tag, $output1;

* * * * switch($element_name) {
* * * * * * * * case "TOTALCHARGES":
* * * * * * * * * * * * $printout = false;
* * * * * * * * * * * * $tag = "";
* * * * * * * * * * * * break;
* * * * }

}

//Defines characterData function
function characterData($xml_parser, $fp) {
* * * * global $printout, $tag, $output1;

* * * * if (($tag=="TOTALCHARGES") && ($printout==true)) {
* * * * * * * * $output1 = $fp;
* * * * * * * * //echo $output;
* * * * }
* * * * return $output1;

}

OK, back to my original question:
Based on some of the replies, I'm renewing my efforts to see what it
will take to fix the many problematic pages that is preventing
migrating to PHP5.
In the meantime, I have to use xml_parser in PHP4.
Is there really no way to tell the xml_parser that I'm looking for the
value of a tag that happens to share the same name as another tag, but
belonging to a separate parent tag?
Like, if this were MySQL, getting the value of "bar" from foo.bar
instead of oof.bar?
Thanks
Jul 21 '08 #15
On Jul 21, 12:12*pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
On Jul 18, 3:12*pm, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
How about:http://www.phpclasses.org/browse/file/22596.html
no extensions to load.
OK, this is ridiculous...how does one install a class?
By the looks of it, this is just a PHP script that maybe I just need
to include() at the top of other pages, but I'm not sure.
The phpclasses site has no help on what to DO with these class pages,
and googling isn't coming up with anything.
This is probably a very stupid question, no, I'm certain it is, but
what do I DO with this simplexlm.class.php?

You've already answered it: You just 'include' or 'require' it.

Micha
OK, thought so--just needed to make sure.
Guess I'm going to have to try to learn that ersatz OOP for PHP4 that
I've avoided learning LOL
Thanks
Jul 21 '08 #16
On Jul 18, 4:08*pm, "n...@celticbear.com" <n...@celticbear.comwrote:
On Jul 18, 3:47*pm, cwdjrxyz <spamtr...@cwdjr.infowrote:
On Jul 18, 2:47*pm, "n...@celticbear.com" <n...@celticbear.comwrote:
On Jul 18, 2:29*pm, Michael Fesser <neti...@gmx.dewrote:
.oO(n...@celticbear.com)
>On Jul 18, 10:51*am, Michael Fesser <neti...@gmx.dewrote:
>I need the value of A's "foo", not B's "foo". But from what I can find
>I can only get the value of the lowest nested tag in a nest. i.e.:
>"foo" or "BAR". Not specifically A or B's "foo".
>Of course you can access every element and every attribute in the tree.
>Just use the right tools.
>I knew it was possible...I was asking for advice HOW. WHAT are the
>right tools?
>Below is the script I'm using. In this case "TOTALCHARGES" is the
>"foo" I'm looking for, but I need it to specifically get A's and not
>B's.
>If someone can point me to where I can find out how, I'd appreciate
>it!
>[...]
>You don't have to write your own parser. Use the SimpleXML extension
>with some XPath expressions to get all the nodes you want.
>In my opinion, writing several lines of script in standard PHP is a
>LOT easier than installing an extension (and learning how to install
>an extension as I've never done that before.)
Why re-invent the wheel? SimpleXML (and the more powerful DOM) are
standard extensions and should be installed and enabled by default in
every recent PHP. We are talking about PHP 5, right?
>IF that's the ONLY way to do what I need to do, then so be it. I'll
>figure out how to install SimpleXML and how to use XPath.
Check phpinfo() to see if SimpleXML is already there (it should be)..
Then check the manual for some examples on how to use it with XPath
syntax to fetch arbitrary elements from an XML tree. Can't get any
easier.
Nope, PHP 4.3.9... there's a reason why our site can't use PHP5
yet...but I don't recall. One of the other developers are saying a
hundred pages will have to be rewritten before we can convert
otherwise it will completely mess up our e-commerce site.
So no, SimpleXML is not found in my phpinfo(). =/
If I remember correctly, it sometimes is possible to have 2 versions
of php on a server. In your case that would mean keeping your current
version of 4 as primary for the extension .php and using the
extension .php5 for the new 5 version. If that can be done and you can
find someone to do it for your server, then you perhaps could keep all
happy. I recently moved my two domains and a subdomain from an old
server that supported php 4 only to a new server that supports php 5
only. There were only a very few minor problems with any of my pages,
and no problems with the php upgrade. Of course some others may have
written code, some of which even predates php4, that causes problems
on an upgrade to php5.

Hmm, cool. Thanks for the reply! I'll check into that.
Also, if you have a personal domain on the server of a host that has
php 5 installed, you can use it for development work if the server at
work only allows php 4.

I have example of an XML parser at http://www.cwdjr.net/php/test/xmlparsedemo.php
. As a demo, it is set to accept only one url in the form, and that is
http://www.cwdjr.net/ram/realmix2.txt . When you paste this url into
the parser box and submit, this XML file will be parsed and displayed.
It is actually a SMIL file of mine which is a special type of XML file
for media presentation. I removed all unneeded white space from a
parsed SMIL file for this demo. Finding such compacted files on the
web is not uncommon, and if you look at the one line compacted code, I
think you will agree that parsing it by hand is something that a judge
might require to punish a hacker convicted of a crime. This demo is
based on some code from a 2008 book by Steven Holzner that covers up
through php 5.2. I added other things that are needed for a valid html
4.01 strict web page, the input form for the url, etc. Holzner has all
of his code demos used in his new book up on the web so that you do
not have to copy them by hand.

Jul 22 '08 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jim | last post by:
I need some help getting started with a .NET web project for a commercial site. I am new to .NET and my understanding of some (but not all) of its concepts is a little sparse. I apologize for the...
0
by: Jim | last post by:
This si a repost, I apologize but perhaps my original inquiry got buried under all the usenet spam... I need some help getting started with a .NET web project for a commercial site. I am new to...
6
by: melanieab | last post by:
Hi, Easy question. It seems to me that I'm following the examples correctly, but apparently I'm not. I'm trying to retrieve the data from a row called "row" and a column called "File". This is...
1
by: rerdavies | last post by:
OS: WIndows Server 2003. Currently logged in user is running with German(German) regional settings. Code fragment: System.Globalization.CultureInfo culture = new...
3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
4
by: sturnfie | last post by:
Hey all, I recently came across the xml.sax libraries and am trying to use them. I am currently making a string variable, and am attempting to pass it into a parser instance as follows: def...
12
by: mistral | last post by:
Can anybody tell me how to get source code of page in iframe? (popup window is clickable image). When I right click on this popup border to view source, i see just as follows <html> <head>...
2
by: hgarg | last post by:
The onpaint() is getting called before calculating the required parameters by listBox1_SelectedIndexChanged function. I tried calling it at the end of this function. But of no use. Due to this issue...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.