Re: [PHP] Parsing XML

2008-12-01 Thread Peter Ford
Per Jessen wrote:
 Ashley Sheridan wrote:
 
 On Fri, 2008-11-28 at 10:15 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:

 Do any of you have a copy of this extension, or failing that, a
 suggestion of how I can parse XML files without having to install
 anything on the remote server, as I do not have that level off
 access to it.
 Parsing XML is best done with XSL - if that's out of the question,
 you're in for a difficult time.


 /Per Jessen, Zürich


 XSL will only allow me to convert it into a different document format,
 which is not what I want as I need to keep a local copy of information
 in a database for searching and sorting purposes. Nathans class allows
 me to have the entire document put into an array tree, which is fine
 for what I need so far.
 
 That's cool, but XSL is still the more appropriate tool IMO.  It does
 exactly what you need - it parses and validates the XML document,
 allows you to extract the bits you need and in virtually any format you
 need - which could be a text document with SQL statements for piping to
 mysql. 
 
 
 /Per Jessen, Zürich
 

I'm with you on this, Per.
You could even use the XSL to construct a bunch of PHP which could be eval'd or
just read in as an include.
Or better yet, if you use the XSL classes, you can register PHP functions and
then call them within your XSL directly. That could potentially handle the
validation you required, and even do the database inserts.

I'm looking into using something like that on a project I'm currently working
on: maybe I can come up with some examples in a couple of days...

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-12-01 Thread Per Jessen
Peter Ford wrote:

 Per Jessen wrote:
 
 That's cool, but XSL is still the more appropriate tool IMO.  It does
 exactly what you need - it parses and validates the XML document,
 allows you to extract the bits you need and in virtually any format
 you need - which could be a text document with SQL statements for
 piping to mysql.
 
 
 /Per Jessen, Zürich
 
 
 I'm with you on this, Per.
 You could even use the XSL to construct a bunch of PHP which could be
 eval'd or just read in as an include.
 Or better yet, if you use the XSL classes, you can register PHP
 functions and then call them within your XSL directly. That could
 potentially handle the validation you required, and even do the
 database inserts.

Yep, that occured to me too. I think XSL can even do quite a bit of the
validation too.

 I'm looking into using something like that on a project I'm currently
 working on: maybe I can come up with some examples in a couple of
 days...

Here's one easy example -

we generate monthly reports for our customers based on the activities of
the most recent month.  The template is an OpenOffice document (well,
several in different languages), which is merged with the activity data
to produce the report in OOo format.  The data is extracted and
formatted as XML. 
The process looks roughly like this:

OOo:template + XML:data - apply XSL - OOo document.  (We then turn the
final OOo document into a PDF which is emailed).  

Of course the same could be achieved using PHP, but instead of a neat
XSL stylesheet, I would have a pile of custom PHP code.

IMO, when you have a need to parse XML or otherwise extract data from
XML, you need a really good reason to disregard XSL.  The only really
good reason I've heard so far was lack of XSL skills, which could be a
real issue.  The learning curve IS quite steep. 


/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-12-01 Thread Ashley Sheridan
On Mon, 2008-12-01 at 11:28 +0100, Per Jessen wrote:
 Peter Ford wrote:
 
  Per Jessen wrote:
  
  That's cool, but XSL is still the more appropriate tool IMO.  It does
  exactly what you need - it parses and validates the XML document,
  allows you to extract the bits you need and in virtually any format
  you need - which could be a text document with SQL statements for
  piping to mysql.
  
  
  /Per Jessen, Zürich
  
  
  I'm with you on this, Per.
  You could even use the XSL to construct a bunch of PHP which could be
  eval'd or just read in as an include.
  Or better yet, if you use the XSL classes, you can register PHP
  functions and then call them within your XSL directly. That could
  potentially handle the validation you required, and even do the
  database inserts.
 
 Yep, that occured to me too. I think XSL can even do quite a bit of the
 validation too.
 
  I'm looking into using something like that on a project I'm currently
  working on: maybe I can come up with some examples in a couple of
  days...
 
 Here's one easy example -
 
 we generate monthly reports for our customers based on the activities of
 the most recent month.  The template is an OpenOffice document (well,
 several in different languages), which is merged with the activity data
 to produce the report in OOo format.  The data is extracted and
 formatted as XML. 
 The process looks roughly like this:
 
 OOo:template + XML:data - apply XSL - OOo document.  (We then turn the
 final OOo document into a PDF which is emailed).  
 
 Of course the same could be achieved using PHP, but instead of a neat
 XSL stylesheet, I would have a pile of custom PHP code.
 
 IMO, when you have a need to parse XML or otherwise extract data from
 XML, you need a really good reason to disregard XSL.  The only really
 good reason I've heard so far was lack of XSL skills, which could be a
 real issue.  The learning curve IS quite steep. 
 
 
 /Per Jessen, Zürich
 
 
I still disagree, as using XSL is essentially converting the XML to
another format, which is then being used by PHP. XSL is great for some
tasks, but for this, I think having a good PHP XMLDoc (or similar type
of) class is better.

On a slightly aside note though, how would you apply the XSL to the XML
using PHP? I know that you can have the stylesheet (XSL) called in from
within the XML document itself, but without being able to change that
XML document, how else can it be done? This could be quite useful to me
in the future.


Ash
www.ashleysheridan.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-12-01 Thread Per Jessen
Ashley Sheridan wrote:

 I still disagree, as using XSL is essentially converting the XML to
 another format, 

Which is all you're doing when you're extracting parts of an XML
document.  

 which is then being used by PHP. XSL is great for some tasks, but for
 this, I think having a good PHP XMLDoc (or similar type of) class is
 better. 

Ash, I'd really like to hear you argue why you think so.

I can't help thinking it's a bit like saying I know there is a compiler
for C-code, but I prefer to convert to assembler by using PHP.  I know
it's not quite that bad, but I hope you get my point.

 On a slightly aside note though, how would you apply the XSL to the
 XML using PHP? 

Roughly like this:  (this is from a project I'm currently working on).

--
// create the xslt processor object
if ( FALSE===($xp=new XSLTProcessor()) ) { print unable to create xslt
engine; return FALSE; }

// Load the XML source
$xml=new DOMDocument;
$xml-loadXML($list);

// then load the XSL stylesheet
$xsl=new DOMDocument;
$xsl-load('getfilebypos.xsl');

// attach the stylesheet
$xp-importStyleSheet($xsl);

$pos=$_GET['pos'];
$xp-setParameter('', array('pos' = $_GET['pos']) );

$file=$xp-transformToXML($xml);


$file in this case is just a single filename, no XML.  My input data has
a list of filenames, the 'pos' argument from the URI identifies one I
need to process.


/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-12-01 Thread Ashley Sheridan
On Mon, 2008-12-01 at 21:35 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:
 
  I still disagree, as using XSL is essentially converting the XML to
  another format, 
 
 Which is all you're doing when you're extracting parts of an XML
 document.  
 
  which is then being used by PHP. XSL is great for some tasks, but for
  this, I think having a good PHP XMLDoc (or similar type of) class is
  better. 
 
 Ash, I'd really like to hear you argue why you think so.
 
 I can't help thinking it's a bit like saying I know there is a compiler
 for C-code, but I prefer to convert to assembler by using PHP.  I know
 it's not quite that bad, but I hope you get my point.
 
  On a slightly aside note though, how would you apply the XSL to the
  XML using PHP? 
 
 Roughly like this:  (this is from a project I'm currently working on).
 
 --
 // create the xslt processor object
 if ( FALSE===($xp=new XSLTProcessor()) ) { print unable to create xslt
 engine; return FALSE; }
 
 // Load the XML source
 $xml=new DOMDocument;
 $xml-loadXML($list);
 
 // then load the XSL stylesheet
 $xsl=new DOMDocument;
 $xsl-load('getfilebypos.xsl');
 
 // attach the stylesheet
 $xp-importStyleSheet($xsl);
 
 $pos=$_GET['pos'];
 $xp-setParameter('', array('pos' = $_GET['pos']) );
 
 $file=$xp-transformToXML($xml);
 
 
 $file in this case is just a single filename, no XML.  My input data has
 a list of filenames, the 'pos' argument from the URI identifies one I
 need to process.
 
 
 /Per Jessen, Zürich
 
 
So here you're advocating loading the XML document into PHP to add an
element, then convert the XML into something else, for PHP to read back
in (not forgetting my original question said I need PHP to do some
operations on the XML.) Do you see why I just wanted a way to extract
the parts of the XML document I needed? This example is actually making
something unnecessarily complex just because XSL is deemed to be the
best way to work with XML.

I'm not saying that XSL is a bad thing, I've used it many times before
to convert various document formats, I just think that for what I
needed, XSL doesn't really suit the task at hand.


Ash
www.ashleysheridan.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-12-01 Thread Per Jessen
Ashley Sheridan wrote:

 Roughly like this:  (this is from a project I'm currently working
 on).
 
 --
 // create the xslt processor object
 if ( FALSE===($xp=new XSLTProcessor()) ) { print unable to create
 xslt engine; return FALSE; }
 
 // Load the XML source
 $xml=new DOMDocument;
 $xml-loadXML($list);
 
 // then load the XSL stylesheet
 $xsl=new DOMDocument;
 $xsl-load('getfilebypos.xsl');
 
 // attach the stylesheet
 $xp-importStyleSheet($xsl);
 
 $pos=$_GET['pos'];
 $xp-setParameter('', array('pos' = $_GET['pos']) );
 
 $file=$xp-transformToXML($xml);
 
 
 $file in this case is just a single filename, no XML.  My input data
 has a list of filenames, the 'pos' argument from the URI identifies
 one I need to process.
 
 
 /Per Jessen, Zürich
 
 
 So here you're advocating loading the XML document into PHP to add an
 element, then convert the XML into something else, for PHP to read
 back in (not forgetting my original question said I need PHP to do
 some operations on the XML.) 

No, not at all.  1) no element is added, 2) the document is not
loaded 'into' PHP and 3) PHP 'reads back' output of about 30 bytes (a
filename + path). 
None of the XSL+XML happens inside of PHP - it's done through the XSL
extension which is essentially all calls to libxslt. 

 Do you see why I just wanted a way to extract the parts of the XML
 document I needed? This example is actually making something
 unnecessarily complex just because XSL is deemed to be the best way to
 work with XML. 

Ash, my example above extracts a single element (specified by 'pos')
from an XML-document - it's all done by a standards-compliant XSLT
style-sheet, and very effectively so.  The 8 lines of PHP code to
invoke the XSL conversion are virtually 'standard' too.  I'm having a
hard time appreciating why that is better done by combining
somebodyelses custom code with your own custom code.

 I'm not saying that XSL is a bad thing, I've used it many times before
 to convert various document formats, I just think that for what I
 needed, XSL doesn't really suit the task at hand.

I understand what you're saying, I just haven't heard a good argument
yet.

Gotta go watch Dr. House on the telly now.  I'll be back tomorow
morning.


/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-12-01 Thread Nathan Rixham

Per Jessen wrote:

Ashley Sheridan wrote:

[/snip] :p

XSL(T)
an xslt processor, along with an XSLT stylesheet, should be used to 
transform XML documents in to other XML, human readable or structured 
documents.


DOM
a class implementing the DOM interface should be used to traverse, 
analyse and extract information from an HTML or valid XML document for 
use in a computer program or to convert values to there primitive 
counterparts.


E4X
ideally E4X should be used where available as this provides native XML 
support, treating xml documents as primitive types and thus providing a 
faster, more acceptable way of using XML as building blocks in a 
computer program.


PHP Support
As far as I am aware PHP does not have any kind of supoort for 
ECMAScript let alone E4X so this can be removed from the discussion as 
quickly as it was entered. Leaving just XSL and DOM.


Non programmatic XML usage:
For all non programatic usage of XML documents (ie transforming the 
document in to html, a human readable document or another xml structure) 
then XSLT should be used.

Examples:
-Integrating the data from an RSS feed into an (X)HTML page and 
outputing it to a client application (non persistant stuctured document)
-Converting an XML Packet into an OOo document and saving it in a file 
system (persistant stuctured document)


Programmatic XML Usage:
For all programmatic usage of XML, when you need to take the data from 
an XML document and use node or attribute values in a program, then the 
DOM API should be used.

Examples:
-Extracting the structured object data encapsulated in a SOAP response 
and using it to instantiate a class for further usage. (non persitant 
structured data for use by a computer program)
-Converting the data values in a structured XML document, (lets say from 
the WOW Armory), into primitive values and then persiting the data into 
database tables. (persitant structured data for use by a computer program)


Grey Areas:
If you are using an ORM which uses XML schemas to define data objects 
then xslt may be the more appropriate choice, this would probably incur 
an extra XSL transformation to then convert the ORM's schema into an object.
One could argue that XSLT could be used to transform the XML document in 
to an SQL string, however this would not allow (or certainly limited 
allowance of) programatic manipulation / validation of the data prior to 
 injection into the SQL string.


Alternatives:
Regex or string parsing on an XML document can often lead to far faster 
but less reliable extraction of data for use in a script, probably so 
common in PHP as it's loosley typed language :p Obviously though if the 
XML document structre changes, you're pretty much stuffed - thus any 
form of native or strongly typed support is a far better option.


Suggestion:
Ashley, TBH the approach I'd take (if I had time) would be to create 
class(es) for the data, then create XML documents representing the 
object structure of each class, write methods using the DOM API to 
extract data from my XML documents and instatiate the class(es) with it. 
At this point I'd have an app that need never change. Then I'd drop in a 
simple XSLT stylesheet to transform the remote XML document in to my 
local structured xml documents and use the XSL processor to run this 
transform. Thus if ever the remote document structure changed all I'd 
have to do is quickly edit the XSLT stylesheet.


But whatever you're cool with, a simple regex xml to array convertor is 
normally the fastest and most transportable way of doing this (ie it'll 
generally work on php 4 and 5 on any server); and when you're not using 
a pre-compiled language you need to give much weight to these things.


Regards!

Nath

[omg i must be bored]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-11-29 Thread Ashley Sheridan
On Fri, 2008-11-28 at 20:39 +0100, Per Jessen wrote:
 Andrew Ballard wrote:
 
  XSL will only allow me to convert it into a different document
  format, which is not what I want as I need to keep a local copy of
  information in a database for searching and sorting purposes. Nathans
  class allows me to have the entire document put into an array tree,
  which is fine for what I need so far.
 
 
  Ash
  www.ashleysheridan.co.uk
  
  A bit over the top, but you could always use XSL to turn it into CSV. 
   LOL
  
  Andrew
 
 Not over the top at all if your database understands CSV.  I think it is
 very odd that no-one else is advocating XSL in this case.  Extracting
 information from an XML file is just another way of converting it,
 which is exactly what XSL is good at.  I can't imagine how using a pile
 of custom PHP code is going to be more efficient than writing a simple
 XSL stylesheet according to recognised standards etc.  Just my opinion
 of course. 
 
 
 /Per Jessen, Zürich
 
 
That would destroy the relationship of the data, as it id in no
structure that would be easy to port to a CSV format.


Ash
www.ashleysheridan.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-11-28 Thread Per Jessen
Ashley Sheridan wrote:

 Do any of you have a copy of this extension, or failing that, a
 suggestion of how I can parse XML files without having to install
 anything on the remote server, as I do not have that level off access
 to it.

Parsing XML is best done with XSL - if that's out of the question,
you're in for a difficult time. 


/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-11-28 Thread Ashley Sheridan
On Fri, 2008-11-28 at 10:15 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:
 
  Do any of you have a copy of this extension, or failing that, a
  suggestion of how I can parse XML files without having to install
  anything on the remote server, as I do not have that level off access
  to it.
 
 Parsing XML is best done with XSL - if that's out of the question,
 you're in for a difficult time. 
 
 
 /Per Jessen, Zürich
 
 
XSL will only allow me to convert it into a different document format,
which is not what I want as I need to keep a local copy of information
in a database for searching and sorting purposes. Nathans class allows
me to have the entire document put into an array tree, which is fine for
what I need so far.


Ash
www.ashleysheridan.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-11-28 Thread Per Jessen
Ashley Sheridan wrote:

 On Fri, 2008-11-28 at 10:15 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:
 
  Do any of you have a copy of this extension, or failing that, a
  suggestion of how I can parse XML files without having to install
  anything on the remote server, as I do not have that level off
  access to it.
 
 Parsing XML is best done with XSL - if that's out of the question,
 you're in for a difficult time.
 
 
 /Per Jessen, Zürich
 
 
 XSL will only allow me to convert it into a different document format,
 which is not what I want as I need to keep a local copy of information
 in a database for searching and sorting purposes. Nathans class allows
 me to have the entire document put into an array tree, which is fine
 for what I need so far.

That's cool, but XSL is still the more appropriate tool IMO.  It does
exactly what you need - it parses and validates the XML document,
allows you to extract the bits you need and in virtually any format you
need - which could be a text document with SQL statements for piping to
mysql. 


/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-11-28 Thread Ashley Sheridan
On Fri, 2008-11-28 at 13:14 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:
 
  On Fri, 2008-11-28 at 10:15 +0100, Per Jessen wrote:
  Ashley Sheridan wrote:
  
   Do any of you have a copy of this extension, or failing that, a
   suggestion of how I can parse XML files without having to install
   anything on the remote server, as I do not have that level off
   access to it.
  
  Parsing XML is best done with XSL - if that's out of the question,
  you're in for a difficult time.
  
  
  /Per Jessen, Zürich
  
  
  XSL will only allow me to convert it into a different document format,
  which is not what I want as I need to keep a local copy of information
  in a database for searching and sorting purposes. Nathans class allows
  me to have the entire document put into an array tree, which is fine
  for what I need so far.
 
 That's cool, but XSL is still the more appropriate tool IMO.  It does
 exactly what you need - it parses and validates the XML document,
 allows you to extract the bits you need and in virtually any format you
 need - which could be a text document with SQL statements for piping to
 mysql. 
 
 
 /Per Jessen, Zürich
 
 
Possibly, but I wouldn't want to trust the end content in such a way;
I'd like to check out the values first. All-in-all, I think XSL is not
the right tool for the job in this case, but it is A way of doing it. 


Ash
www.ashleysheridan.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML

2008-11-28 Thread Andrew Ballard
On Fri, Nov 28, 2008 at 5:45 AM, Ashley Sheridan
[EMAIL PROTECTED] wrote:
 On Fri, 2008-11-28 at 10:15 +0100, Per Jessen wrote:
 Ashley Sheridan wrote:

  Do any of you have a copy of this extension, or failing that, a
  suggestion of how I can parse XML files without having to install
  anything on the remote server, as I do not have that level off access
  to it.

 Parsing XML is best done with XSL - if that's out of the question,
 you're in for a difficult time.


 /Per Jessen, Zürich


 XSL will only allow me to convert it into a different document format,
 which is not what I want as I need to keep a local copy of information
 in a database for searching and sorting purposes. Nathans class allows
 me to have the entire document put into an array tree, which is fine for
 what I need so far.


 Ash
 www.ashleysheridan.co.uk

A bit over the top, but you could always use XSL to turn it into CSV.   LOL

Andrew


Re: [PHP] Parsing XML

2008-11-28 Thread Per Jessen
Andrew Ballard wrote:

 XSL will only allow me to convert it into a different document
 format, which is not what I want as I need to keep a local copy of
 information in a database for searching and sorting purposes. Nathans
 class allows me to have the entire document put into an array tree,
 which is fine for what I need so far.


 Ash
 www.ashleysheridan.co.uk
 
 A bit over the top, but you could always use XSL to turn it into CSV. 
  LOL
 
 Andrew

Not over the top at all if your database understands CSV.  I think it is
very odd that no-one else is advocating XSL in this case.  Extracting
information from an XML file is just another way of converting it,
which is exactly what XSL is good at.  I can't imagine how using a pile
of custom PHP code is going to be more efficient than writing a simple
XSL stylesheet according to recognised standards etc.  Just my opinion
of course. 


/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Parsing XML

2008-11-27 Thread Ashley Sheridan
Hi All,

I've run into a bit of a problem. I need to parse some fairly detailed
XML files from a remote website. I'm pulling in the remote XML using
curl, and that bit is working fine. The smaller XML documents were easy
to parse with regular expressions, as I only needed  bit of information
out of them.

The live server I'm eventually putting this onto only has domxml for
working with XML. I've been trying to find the pecl extension for this
to install on my local machine, but the pecl.php.net site is a bit
nerfed for this extension (I'm getting a file not found error message.)

Do any of you have a copy of this extension, or failing that, a
suggestion of how I can parse XML files without having to install
anything on the remote server, as I do not have that level off access to
it.

Thanks
Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Parsing XML with DTD

2007-11-22 Thread Skip Evans

Hey all,

I've been asked if it's possible to parse XML 
files given a DTD file that describes the elements 
within it, so I've been looking through the docs 
at php.net.


So far I've found this:

http://us.php.net/manual/en/ref.xml.php

Which has some samples on, but nothing that I see 
will take a DTD file and parse the XML accordingly.


I'm thinking something like this is probably possible.

I'm still looking through the docs, but if anyone 
can point me in the right direction would be 
appreciated.


Thanks!
Skip

--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX  DHTML development framework.
http://phpenguin.bigskypenguin.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML with DTD

2007-11-22 Thread Skip Evans

Hey Jochem  all,

Thanks much for this tip. I will check it out.

A little further reading looks like PEAR provides 
some XML and DTD capabilities? Anyone have any 
experience with this?


Also, the reason I asked about the DTD is that 
these XML files are really extensive, providing 
lots of varied info about literature, history, a 
whole ton of topics, so I thought parsing the DTD 
will be necessary to know what kinds of data I'm 
really looking at.


I'll check out Jochem's suggestion now, but would 
also like to hear if anyone has used PEAR, and 
also about the need for the DTD for big, 
complicated XML files.


Would it be helpful if I pasted one of the XML 
files to the list?


Thanks again!
Skip


Jochem Maas wrote:

Skip Evans wrote:

Hey all,

I've been asked if it's possible to parse XML files given a DTD file
that describes the elements within it, so I've been looking through the
docs at php.net.

So far I've found this:

http://us.php.net/manual/en/ref.xml.php

Which has some samples on, but nothing that I see will take a DTD file
and parse the XML accordingly.


use php5 and the DOM extension (not XML and not DOMXML):

http://us.php.net/manual/en/ref.dom.php


I'm thinking something like this is probably possible.

I'm still looking through the docs, but if anyone can point me in the
right direction would be appreciated.

Thanks!
Skip






--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX  DHTML development framework.
http://phpenguin.bigskypenguin.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML with DTD

2007-11-22 Thread Per Jessen
Skip Evans wrote:

 I've been asked if it's possible to parse XML files given a DTD file
 that describes the elements within it, 

Yes it is. 

 Which has some samples on, but nothing that I see
 will take a DTD file and parse the XML accordingly.
 I'm thinking something like this is probably possible.

You don't actually need to DTD to parse it, but it does help with the
syntax-check of the contents.


/Per Jessen, Zürich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML with DTD

2007-11-22 Thread Jochem Maas
Skip Evans wrote:
 Hey all,
 
 I've been asked if it's possible to parse XML files given a DTD file
 that describes the elements within it, so I've been looking through the
 docs at php.net.
 
 So far I've found this:
 
 http://us.php.net/manual/en/ref.xml.php
 
 Which has some samples on, but nothing that I see will take a DTD file
 and parse the XML accordingly.

use php5 and the DOM extension (not XML and not DOMXML):

http://us.php.net/manual/en/ref.dom.php

 
 I'm thinking something like this is probably possible.
 
 I'm still looking through the docs, but if anyone can point me in the
 right direction would be appreciated.
 
 Thanks!
 Skip
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Parsing XML with DTD

2007-11-22 Thread Andrés Robinet
 -Original Message-
 From: Skip Evans [mailto:[EMAIL PROTECTED]
 Sent: Thursday, November 22, 2007 5:35 PM
 To: Jochem Maas
 Cc: PHP-General
 Subject: Re: [PHP] Parsing XML with DTD
 
 Hey Jochem  all,
 
 Thanks much for this tip. I will check it out.
 
 A little further reading looks like PEAR provides
 some XML and DTD capabilities? Anyone have any
 experience with this?
 
 Also, the reason I asked about the DTD is that
 these XML files are really extensive, providing
 lots of varied info about literature, history, a
 whole ton of topics, so I thought parsing the DTD
 will be necessary to know what kinds of data I'm
 really looking at.
 
 I'll check out Jochem's suggestion now, but would
 also like to hear if anyone has used PEAR, and
 also about the need for the DTD for big,
 complicated XML files.
 
 Would it be helpful if I pasted one of the XML
 files to the list?
 
 Thanks again!
 Skip
 
 
 Jochem Maas wrote:
  Skip Evans wrote:
  Hey all,
 
  I've been asked if it's possible to parse XML files given a DTD file
  that describes the elements within it, so I've been looking through
 the
  docs at php.net.
 
  So far I've found this:
 
  http://us.php.net/manual/en/ref.xml.php
 
  Which has some samples on, but nothing that I see will take a DTD
 file
  and parse the XML accordingly.
 
  use php5 and the DOM extension (not XML and not DOMXML):
 
  http://us.php.net/manual/en/ref.dom.php
 
  I'm thinking something like this is probably possible.
 
  I'm still looking through the docs, but if anyone can point me in
 the
  right direction would be appreciated.
 
  Thanks!
  Skip
 
 
 
 
 --
 Skip Evans
 Big Sky Penguin, LLC
 503 S Baldwin St, #1
 Madison, WI 53703
 608-250-2720
 http://bigskypenguin.com
 =-=-=-=-=-=-=-=-=-=
 Check out PHPenguin, a lightweight and versatile
 PHP/MySQL, AJAX  DHTML development framework.
 http://phpenguin.bigskypenguin.com/
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


I believe the DTD would only be helpful to you if you are validating the XML
stream yourself... If you only need to know what kind of data you are
looking at, you can just grab the doctype property for the DocumentElement
and compare it to a set of (known by you) predefined doctypes... After that,
you can implement a walk through the elements of the XML stream knowing what
you can expect about it. This will simplify your programming logic, unless
there are infinite doctypes for the data source in question.

For validation, you can use this
http://us.php.net/manual/en/function.dom-domdocument-validate.php (only if
you are interested in the document being well formed according to the DTD)

For identifying the DTD, check the DocumentElement doctype property and
the DOMDocumentType class http://us.php.net/manual/en/ref.dom.php.

Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308
| TEL 954-607-4207 | FAX 954-337-2695 | 
Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE:
bestplace |  Web: bestplace.biz  | Web: seo-diy.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing XML with php

2005-05-16 Thread Christian Stocker
On 5/12/05, Burhan Khalid [EMAIL PROTECTED] wrote:
 Merlin wrote:
  Hi there,
 
  I am curious if PHP is now able to pars xml without aditional tools like
  xmlrpc.
  If yes which version is required? Is the current php 4.x tree sufficient?
 
 4.x requires the expat parser (so I guess it would require external libs).

Wrong, the exapt library  is included in PHP 4.

 5.x has the simplexml extension (which I believe requires no external libs).

Wrong, libxml2 is needed as external library for having *any* XML
support in PHP 5 (if you have libxml2 installed, you should get SAX
(aka ext/xml), DOM and simplexml support out of the box)

chregu
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
phone +41 1 240 56 70 | mobile +41 76 561 88 60  | fax +41 1 240 56 71
http://www.bitflux.ch  |  [EMAIL PROTECTED]  |  gnupg-keyid 0x5CE1DECB

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Parsing XML with php

2005-05-12 Thread Merlin
Hi there,
I am curious if PHP is now able to pars xml without aditional tools like xmlrpc.
If yes which version is required? Is the current php 4.x tree sufficient?
Thanx, Merlin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Parsing XML with php

2005-05-12 Thread Burhan Khalid
Merlin wrote:
Hi there,
I am curious if PHP is now able to pars xml without aditional tools like 
xmlrpc.
If yes which version is required? Is the current php 4.x tree sufficient?
4.x requires the expat parser (so I guess it would require external libs).
5.x has the simplexml extension (which I believe requires no external libs).
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] parsing xml the right way

2004-04-01 Thread Merlin
Hi there,

I think I am parsing xml documents the wrong way.
There must be a better way to access the results laterone like objects.
For example I would like to search in a free form for a city name
inside an xml document and php should return the country name
and continent.
This is the xml structure:
Country size=4
countryNameAndorra/countryName
countryCodeAD/countryCode
countryContinentEurope/countryContinent
Cities size=4
cityEncamp/city
cityEscaldes-Engordany/city
cityOrdino/city
citySoldeu/city
/Cities
/Country
Has anybody a good hint for me?

Thanx in advance,

Merlin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Parsing XML CDATA errors?

2003-03-30 Thread Toby Coleridge
I am trying to parse an XML file that looks like the following
snippet:

latest_news
item id=1
date12/03/03/date
titleNew benefits to members/title
description
![CDATA[hello :)BRHello ]]
/description
/item
/latæst_news

however it will not parse (doesnt display anything) when I put the
CDATA line on the same line as the description and put the close tag
on the same line as well then all works fine, this is ok in this
exmple but it is of little use when the CDATA contains many lines or
is complicated etc is there a way to solve this? I have attaced the
PHP code I am using below but can not see anything wrong with it ??

Many Thanks
Toby.
?php
if( ! ($fp = fopen( ./news.xml , r )) )
  die(Couldn't open xml file!);
$counter = 0;
$person_data = array();
$xml_current_tag_state = '';

function startElementHandler( $parser, $element_name, $element_attribs ) {
  global $counter;
  global $person_data;
  global $xml_current_tag_state;
  if( $element_name == ITEM ) {
$person_data[$counter][id] = $element_attribs[ID];
  } else {
$xml_current_tag_state = $element_name;
  }
}

function endElementHandler( $parser, $element_name ) {
  global $counter;
  global $person_data;
  global $xml_current_tag_state;
  $xml_current_tag_state = '';
  
  if( $element_name == ITEM ) {
$counter++;
  }
}

function characterDataHandler( $parser , $data ) {
  global $counter;
  global $person_data;
  global $xml_current_tag_state;
  if( $xml_current_tag_state == '' )
return;
  if( $xml_current_tag_state == DATE ) {
$person_data[$counter][date] = $data;
  }
  if( $xml_current_tag_state == TITLE ) {
$person_data[$counter][title] = $data;
  }
  if( $xml_current_tag_state == DESCRIPTION ) {
$person_data[$counter][description] = $data;
  }
}
if( !($xml_parser = xml_parser_create()) )
  die(Couldn't create XML 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; // get out of while loop if we're done with the file
  }
}
xml_parser_free($xml_parser);
?

!DOCTYPE HTML PUBLIC -//IETF//DTD HTML//EN
HTML
HEAD
  TITLEParsing the Sample XML File/TITLE
/HEAD

BODY BGCOLOR=#ff

?php
for( $i=0 ; $i  $counter ; ++$i ) {
  echo Date:nbsp;nbsp; . $person_data[$i][date] . BR\n;
  echo Title:nbsp;nbsp; . $person_data[$i][title] . BR\n;
  echo Description:nbsp;nbsp; . $person_data[$i][description] . BR\n;
  echo BR\n;
}

?

/BODY
/HTML

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP] Parsing XML files, logic involved...

2002-11-27 Thread Jeff Lewis
I have to write a script to parse XML files we receive daily. The XML files are all 
individual stories but there is an index page that comes with each batch that contains 
blocks of information for each story as follows (below). I need to run through this 
index file and for each story I need to grab the NewsItemID, the Time, and then the 
SourceFilePath.

From there I need to then open up the individual stories and do some formatting but 
for now I need to get by this :) I was planning on line by line through the file but 
am not sure how I would go about grabbing the information I require. Sometimes there 
is a SourceFilepath but sometimes its missing.

Any help would be greatly appreciated.

ContentItem

Comment NewsItemID=780023,   Time=28-05-02 13:43/
Comment SlugLine=Canada-U.S.-Protectionism/

DataContent
CPOnlineFile Type=IndexStoryItem
JavaScript ScriptLanguage=JavaScriptLanguage;CPJavaScriptOpenWindow;/JavaScript
CPIndexStoryHeadChretien pushes Bush on softwood, agriculture, but gets no 
promises/CPIndexStoryHead
CPStory
CPStoryPara Number=1 ParaSpace=FALSE
(CP) - Prime Minister Jean Chretien said he pressed U.S. President George W. Bush on 
Tuesday to address festering trade disputes between the two countries, but got no 
assurances that disagreements over softwood lumber or agricultural subsidies would be 
resolved. Chretien, who raised the matters after a NATO meeting in the Italian 
capital, said he was very forceful with Bush. But he said the president blamed 
Congress for the logjam.

/CPStoryPara
CPStoryPara Number=2 ParaSpace=FALSE
It's always like that when you deal with the president of the United States: 'Yes, 
but the Congress and the Senate . . . ' In Canada you blame the prime minister or you 
congratulate the prime minister because he cannot pass the buck to anyone else.

/CPStoryPara
/CPStory
CPLink Type=StoryFile Number=1 SourceFilePath=./n052814A.xml/

/CPOnlineFile
/DataContent
/ContentItem



Re: [PHP] Parsing XML files, logic involved...

2002-11-27 Thread Khalid El-Kary
hi,
If you are sure that all your files come with attributes double quoted (not 
single quoted) you may want to use this parser class:

http://creaturesx.ma.cx/kxparse/

hint: use the function has_attribute() to verify whether an attribute is 
available

Regards,
khalid

_
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Parsing XML into PHP array.

2002-08-02 Thread Scott Fletcher

I'm having trouble getting the XML string to be broken up into the PHP
array.  Here's how it work.  I send the XML request in a string to the
credit bureau through cURL and vice versa.  Most of the PHP scripting I
found everywhere spoke about breaking up the xml tag into the array only
when they come from the file and is use for parsing.  Problem here is it is
illegal to store the credit inquiry information to a file on the server
except temporary storing it in the RAM but then it will have to be destroyed
when it is done.  I don't need to parse it, just want to use the tag name as
the name in the array with the data from the tag as data to that array name.
What is the work around for this??

Thanks,
 FletchSOD



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Parsing XML into PHP array.

2002-08-02 Thread Analysis Solutions

 I send the XML request in a string to the
 credit bureau through cURL and vice versa.  Most of the PHP scripting I
 found everywhere spoke about breaking up the xml tag into the array only
 when they come from the file and is use for parsing.

The example on my page you looked at does get the stuff from a file, BUT,
it takes that content and puts it into a string.  All the xml_parse()
function needs is the string.  So, just feed it the string you get back
from the agency.

--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] PHP parsing XML from Shoutcast

2002-05-19 Thread Johan Ekström

Anyone that has knowledge about this program, regarding it's XML output and
php fetching that info and placing it on a php-page for user's to view?





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Parsing XML

2002-04-30 Thread Fredrik Arild Takle

Hi,

this might be a silly question, but I really haven't used XML alot with PHP.
I've parsed som XML, when I do xml_parse it outputs the html-codes.

I want to make a variable out of it.. I've tried $output = xml_parse();



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] parsing xml/string

2002-01-16 Thread Sandeep Murphy

Hi,

I have an xml output with tags like sessionid123/sessionid
usersands/sands  

I could parse the output using expat to display it the way i want or as a
string but what I need is to store the values separately in different
variables like $id for sessionid, $user for user and so on.. to be
manipulated later...

Any suggestions??

TIa,

sandeep

-- 
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] parsing xml/string

2002-01-16 Thread Hank Marquardt

I guess I'd setup a global array $TAGS, create an entry in the array
with your open_tag handle, $TAGS[$tagnamepassedtohandler], use the data
handler to populate it $TAGS[$currenttag].=$data; 

When you're done parsing the xml you have one big array with all the
tags that you can either use extract() on or use the $$ (variable
variable notation to create individual namespace entries.

On Wed, Jan 16, 2002 at 05:25:48PM -, Sandeep Murphy wrote:
 Hi,
 
 I have an xml output with tags like sessionid123/sessionid
 usersands/sands  
 
 I could parse the output using expat to display it the way i want or as a
 string but what I need is to store the values separately in different
 variables like $id for sessionid, $user for user and so on.. to be
 manipulated later...
 
 Any suggestions??
 
 TIa,
 
 sandeep
 
 -- 
 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]
 

-- 
Hank Marquardt [EMAIL PROTECTED]
http://web.yerpso.net
GPG Id: 2BB5E60C
Fingerprint: D807 61BC FD18 370A AC1D  3EDF 2BF9 8A2D 2BB5 E60C
*** Web Development: PHP, MySQL/PgSQL - Network Admin: Debian/FreeBSD
*** PHP Instructor - Intnl. Webmasters Assn./HTML Writers Guild 
*** Beginning PHP -- Starts January 7, 2002 
*** See http://www.hwg.org/services/classes

-- 
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]




[PHP] Parsing XML

2001-11-13 Thread Michael Harris

Can anybody tell me if there is a way to build an array or some other
means of collecting the attributes from the Start Element Handler so I
can return them back to my main application?

Thanks for any help,
-Mike


-- 
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] Parsing XML

2001-11-13 Thread Ben Gollmer

Do something like this:

function parseXML($xmlFile)
{
$theParser = xml_parser_create();
xml_set_element_handler($theParser, startElementHandler, 
endElementHandler);
//parse your XML here

return $attributeArray;
}

function startElementHandler($theParser, $theTag, $theAttrs)
{
global $attributeArray;

//do your attribute handling here; maybe something like this
$attributeArray[] = $theAttrs;
}


Ben


On Tuesday, November 13, 2001, at 07:34 PM, Michael Harris wrote:

 Can anybody tell me if there is a way to build an array or some other
 means of collecting the attributes from the Start Element Handler so I
 can return them back to my main application?

 Thanks for any help,
 -Mike


 --
 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]




-- 
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] Parsing XML

2001-11-13 Thread Ben Gollmer

Oops, forgot a line:

On Tuesday, November 13, 2001, at 08:58 PM, Ben Gollmer wrote:

 Do something like this:

 function parseXML($xmlFile)
 {
global $attributeArray;

   $theParser = xml_parser_create();
   xml_set_element_handler($theParser, startElementHandler, 
 endElementHandler);
   //parse your XML here

   return $attributeArray;
 }

 function startElementHandler($theParser, $theTag, $theAttrs)
 {
   global $attributeArray;

   //do your attribute handling here; maybe something like this
   $attributeArray[] = $theAttrs;
 }


 Ben


 On Tuesday, November 13, 2001, at 07:34 PM, Michael Harris wrote:

 Can anybody tell me if there is a way to build an array or some other
 means of collecting the attributes from the Start Element Handler so I
 can return them back to my main application?

 Thanks for any help,
 -Mike


 --
 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: php-list-
 [EMAIL PROTECTED]




 -- 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]




-- 
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]




[PHP] parsing XML data with ampersands ()

2001-11-12 Thread bill

When parsing XML data, the CDATA sometimes contains an ampersand ().

The XML parser sends this as two events, one before the ampersand and
one after.  That yields two data sections (when there is only one).

Ideas on how to keep them together?

Is this a bug?

kind regards,

bill hollett


-- 
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] parsing XML data with ampersands ()

2001-11-12 Thread Jon Haworth

Change your CDATA so it contains amp; instead of 

HTH
Jon


-Original Message-
From: bill [mailto:[EMAIL PROTECTED]]
Sent: 12 November 2001 15:51
To: [EMAIL PROTECTED]
Subject: [PHP] parsing XML data with ampersands ()


When parsing XML data, the CDATA sometimes contains an ampersand ().

The XML parser sends this as two events, one before the ampersand and
one after.  That yields two data sections (when there is only one).

Ideas on how to keep them together?

Is this a bug?

kind regards,

bill hollett


**
'The information included in this Email is of a confidential nature and is 
intended only for the addressee. If you are not the intended addressee, 
any disclosure, copying or distribution by you is prohibited and may be 
unlawful. Disclosure to any party other than the addressee, whether 
inadvertent or otherwise is not intended to waive privilege or confidentiality'

**

-- 
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]




[PHP] parsing XML turorials, suggestions

2001-10-29 Thread bill

Need to get started parsing XML documents.  I've developed a program to
write them XML a database, but now I need to read them to obtain, for
example, the (cdata) value of title which is nested inside book,
etc.

What's the best place to start?  Does DOMXML have a future?

Tutorials?

Suggestions?

kind regards,

bill hollett


-- 
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] parsing XML turorials, suggestions

2001-10-29 Thread Christian Reiniger

On Monday 29 October 2001 16:25, bill wrote:
 Need to get started parsing XML documents.  I've developed a program to
 write them XML a database, but now I need to read them to obtain, for
 example, the (cdata) value of title which is nested inside book,
 etc.

 What's the best place to start?  Does DOMXML have a future?

Sure. But it's a bit overkill if you just want to read XML (sequentially).
http://php.net/manual/en/ref.xml.html

-- 
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)

This is JohnC IMHO, I compaired tri-word groupings here and in his plan
and got a good match.

- /. posting discussing the likelihood that an AC post that claimed to be
posted by John Carmack during his honeymoon (and having the login info at
home) was actually from him.

--
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]




[PHP] PArsing xml document with php

2001-07-11 Thread Francis Fillion

I'm trying to parse a xml document in php and to get in an array, but it
sometime give me really strange result.

Like if I have: 

$simple= item test /item;
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$simple,$vals,$index);
xml_parser_free($parser);


It will give me this in $index
Array
(
[ITEM] = Array
(
[0] = 0
)

)
###
And this in $vals
Array
(
[0] = Array
(
[tag] = ITEM
[type] = cdata
[level] = 1
[value] = *test 
)

)


What does the * means? Why is it there? Have any other's have
experienced any problem with php and xml?


Compiled with those option:
./configure   --enable-track-vars  --with-gd=../gd-1.8.3 
--with-swf=../php4-swf  --with-mysql   --enable-xslt
--with-xslt-sablot=../Sablot-0.60  --with-apxs
--enable-sablot-errors-descriptive --with-xml
--with-dom=/usr/include/libxml --with-zlib

ON Apache 1.3.20, php 4.0.6 and redhat 6.2

-- 
Francis Fillion, BAA SI
Broadcasting live from his linux box.
And the maintainer of http://www.windplanet.com

-- 
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]




[PHP] Parsing XML CDF format in PHP3 - Stumbling over ?

2001-03-29 Thread Mike Gifford

Hello,

For some reason I am now having real difficulties removing and parsing some XML
files.  I think that if I can just strip out the ?  ? that I should be able
to parse the XML (.CDF) file.  This should do it:
$pagetext = eregi_replace('?','',$pagetext);
$pagetext = eregi_replace('?','',$pagetext);

I've attached the whole CDF file at the bottom of this message.  However, I
think that the following should strip out the offending part as well:
$pagetext = eregi_replace('.*/TITLE','',$pagetext);

Unfortunately, for some reason it just isn't working for me.  I have other
scripts working just fine using similar code (on the same page).  However, this
just isn't working for me today.  

Any suggestions on what I'm overlooking would be great.

Mike

?xml version="1.0"?
CHANNEL HREF="http://cbc.ca/business/"
TITLE CBC News /TITLE
ITEM
HREF="http://cbc.ca/cgi-bin/templates/view.cgi?/news/2001/03/29/stocksopen_010329"
 TITLETSE at lowest close in 16 months/TITLE
 ABSTRACT
More negative news from the technology sector helped drive the TSE 300  to its
lowest close in 16 months Thursday. And the tech-heavy Nasdaq  closed at its
lowest level since November 1998. 
 /ABSTRACT
/ITEM
ITEM
HREF="http://cbc.ca/cgi-bin/templates/view.cgi?/news/2001/03/29/OSCfakescam_010329"
 TITLEOSC sets up fake Web site to show online investing dangers /TITLE
 ABSTRACT
A phoney Internet site that promised investors high returns with low  risk drew
thousands of visitors during an investigation run by the  Ontario Securities
Commission. 
 /ABSTRACT
/ITEM
ITEM
HREF="http://cbc.ca/cgi-bin/templates/view.cgi?/news/2001/03/28/cdnx010328"
 TITLECanadian Venture Exchange approves TSE takeover plan/TITLE
 ABSTRACT
The boards of directors of both the Toronto Stock Exchange and the  Canadian
Venture Exchange (CDNX) have both voted in principle to approve  the takeover of
the CDNX by the TSE. 
 /ABSTRACT
/ITEM
/CHANNEL

-- 
Mike Gifford, OpenConcept Consulting, http://openconcept.ca
Offering everything your organization needs for an effective web site.
Featured Client: http://www.aboriginalrightscoalition.ca/
If a book doesn't make us better, then what on earth is it for? - Alice Walker

-- 
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] Parsing XML CDF format in PHP3 - Stumbling over ?

2001-03-29 Thread David Robley

On Fri, 30 Mar 2001 14:34, Mike Gifford wrote:
 Hello,

 For some reason I am now having real difficulties removing and parsing
 some XML files.  I think that if I can just strip out the ?  ? that
 I should be able to parse the XML (.CDF) file.  This should do it:
   $pagetext = eregi_replace('?','',$pagetext);
   $pagetext = eregi_replace('?','',$pagetext);

 I've attached the whole CDF file at the bottom of this message. 
 However, I think that the following should strip out the offending part
 as well: $pagetext = eregi_replace('.*/TITLE','',$pagetext);

 Unfortunately, for some reason it just isn't working for me.  I have
 other scripts working just fine using similar code (on the same page). 
 However, this just isn't working for me today.

 Any suggestions on what I'm overlooking would be great.

 Mike

I'm no regex guru but isn't the ? a special character? Try using 
str_replace instead; it should be quicker also.

-- 
David Robley| WEBMASTER  Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES  | http://www.nisu.flinders.edu.au/
AusEinet| http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA

-- 
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]




[PHP] Parsing XML

2001-02-10 Thread Steve Haemelinck

I want to parse an XML from nasdaq, but I allways get a blank page when
doing so.
I also get the notice: undefined index when parsing.  What does this mean?


-- 
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]




[PHP] Parsing XML the Sequel :)

2001-02-10 Thread Steve Haemelinck

The page I want to parse is:

http://213.224.136.110:8080/test.xml

And this is my code:

?php

//Define Opening Tags of XML
$open_tags = array(
'STORY' = 'nasdaqamex-dot-com',
'STOCK_NAME' = 'issue-name',
'LAST_SALE' = 'last-sale-price',
'PREVIOUS_CLOSE' = 'previous-close-price',
'NET_CHANGE_PCT' = 'net-change-pct',
'STOCK_URL' = 'issuer-web-site-url');

//Define Closing Tags of XML
$close_tags = array(
'STORY' = '/nasdaqamex-dot-com',
'STOCK_NAME' = '/issue-name',
'LAST_SALE' = '/last-sale-price',
'PREVIOUS_CLOSE' = '/previous-close-price',
'NET_CHANGE_PCT' = '/net-change-pct',
'STOCK_URL' = '/issuer-web-site-url');


// handles the attributes for opening tags
// $attrs is a multidimensional array keyed by attribute
// name and having the value of that attribute
function startElement($parser, $name, $attrs=''){
global $open_tags, $temp, $current_tag;

$current_tag = $name;
if ($format = $open_tags[$name]){
switch($name){
case 'STORY':
echo 'New Story: ';
break;
default:
break;
}
}
}

// $current_tag lets us know what tag we are currently
// dealing with - we use that later in the characterData
// function.
//
// when we see a /STORY we know that it is time to
// flush our temp variables and prepare to move onto
// the next one
function endElement($parser, $name, $attrs=''){
global $close_tags, $temp, $current_tag;

if ($format = $close_tags[$name]){
switch($name){
case 'STORY':
return_page($temp);
$temp = '';
break;
default:
break;
}
}
}

// this function is passed data between elements
// theu $data would equal 'Title Here'
// in the line TITLETitle Here/TITLE
function characterData($parser, $data){
global $current_tag, $temp, $catID;

switch($current_tag){
case 'STOCK_NAME':
$temp['stock_name'] = $data;
$current_tag = '';
break;
case 'LAST_SALE':
$temp['last_sale'] = $data;
$current_tag = '';
break;
default:
break;
}
}

function return_page() {
global $temp;

echo 'o A
HREF="'.$temp['stock_name'].'"'.$temp['last_sale'].'/ABR';
}

// what are we parsing?
$xml_file = 'test.xml';

// declare the character set - UTF-8 is the default
$type = 'UTF-8';

// create our parser
$xml_parser = xml_parser_create($type);

// set some parser options
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');

// this tells PHP what functions to call when it finds an element
// these funcitons also handle the element's attributes
xml_set_element_handler($xml_parser, 'startElement','endElement');

// this tells PHP what function to use on the character data
xml_set_character_data_handler($xml_parser, 'characterData');

if (!($fp = fopen($xml_file, 'r'))) {
die("Could not open $xml_file for parsing!\n");
}

// loop through the file and parse baby!
while ($data = fread($fp, 4096)) {
if (!($data = utf8_encode($data))) {
echo 'ERROR'."\n";
}
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf( "XML error: %s at line %d\n\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}

xml_parser_free($xml_parser);

//Just to see if it has done something
echo 'yahoo';
?


-- 
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] Parsing XML the Sequel :)

2001-02-10 Thread Matt McClanahan

On Sat, Feb 10, 2001 at 07:37:32PM +0100, Steve Haemelinck wrote:

 The page I want to parse is:
 
 http://213.224.136.110:8080/test.xml
 
 And this is my code:
 
 ?php
 
 //Define Opening Tags of XML
 $open_tags = array(
 'STORY' = 'nasdaqamex-dot-com',
 'STOCK_NAME' = 'issue-name',
 'LAST_SALE' = 'last-sale-price',
 'PREVIOUS_CLOSE' = 'previous-close-price',
 'NET_CHANGE_PCT' = 'net-change-pct',
 'STOCK_URL' = 'issuer-web-site-url');

(snip)

 // handles the attributes for opening tags
 // $attrs is a multidimensional array keyed by attribute
 // name and having the value of that attribute
 function startElement($parser, $name, $attrs=''){
 global $open_tags, $temp, $current_tag;
 
 $current_tag = $name;
 if ($format = $open_tags[$name]){
 switch($name){
 case 'STORY':
 echo 'New Story: ';
 break;
 default:
 break;
 }
 }
 }

This probably isn't doing what you think it's doing.  When the parser
hits a new element tag, it will pass the parser object, element name,
and its attributes to startElement().  $name will be the name of the
element.  Equity-quote, issue-name, etc.  So when you go to look for
$open_tags[$name], you won't find anything because the array is keyed
to STORY, STOCK_NAME, etc.  It looks like you're expecting the array to
be backwards.  Switching the keys/values and removing the , /,  would
be enough to make it work.

HTH,
Matt

-- 
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]