Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

howto? parse multiple xml strings with domxml
Hi,

I'm really  with all these extensions and libraries in PHP. We
had a stable setup with Sablotron and could parse multiple XML strings
in one operation, but now we switched over to PHP5, dropped Sablotron
(it's way too slow) and try to get things alive again, but this seems
an impossible mission.

We worked with Sablotron before but switched over to the libxslt
library on PHP5 to perform XSL transformations. We used the wrapper
code found on http://be.php.net/xsl so that our old xslt_ functions
continued to work.

Now, with Sablotron we used to parse multiple XML documents as strings
and one XSL file from file. With libxslt it doesn't seem possible
parsing XML documents as strings.

This is the old method which worked fine, using Sablotron:

$args["/list_docu"] = "<content>some xml</content>";
$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $args,
$params);

This node could then be access with XSL:
<xsl:for-each select="document('arg:/list_docu')/content">

When I run this code using libxslt/PHP5 and the wrapper I get the
error:
Warning: I/O warning : failed to load external entity "arg:/list_docu"

This is because the XML documents must be saved on disk I guess.
Isn't there any way to load the XML documents as strings???

Grtz,

Bart

Report this thread to moderator Post Follow-up to this message
Old Post
bc
12-21-04 08:55 AM


Re: howto? parse multiple xml strings with domxml
bc wrote:
> I'm really  with all these extensions and libraries in PHP. We
> had a stable setup with Sablotron and could parse multiple XML strings
> in one operation, but now we switched over to PHP5, dropped Sablotron
> (it's way too slow) and try to get things alive again, but this seems
> an impossible mission.
>

Have you visited the XSL manual page at http://nl.php.net/xsl ?

In the user contributes section, I have added some wrapper code a while ago,
which might be useful.

Just search for "jw at jwscripts dot com".


JW




Report this thread to moderator Post Follow-up to this message
Old Post
Janwillem Borleffs
12-21-04 08:55 AM


Re: howto? parse multiple xml strings with domxml
Janwillem Borleffs wrote:
> Have you visited the XSL manual page at http://nl.php.net/xsl ?
>
> In the user contributes section, I have added some wrapper code a
> while ago, which might be useful.
>
> Just search for "jw at jwscripts dot com".
>

There must be a better way, but until I have found one, the following
workaround could do the trick for now:

In the code mentioned before, replace the following sections:

Change:

// Start the transformation
$processed = $xsltproc->transformToXML($xml);

Into:

// Start the transformation
$processed = @$xsltproc->transformToXML($xml);

Now the call would be as follows:

$html = xslt_process(
$xsltproc,
'arg:/_xml',
'arg:/_xsl',
null,
$arguments,
array('document'=>$arguments['/_xml'])
);

This would assign the XML contents to the fifth argument, setting it as an
XSL parameter.

In the XSLT, you should then able to do the following:

<xsl:param name="document" />
<xsl:template match="/">

<xsl:for-each select="document($document)/content">
...
</xsl:for-each>

This is more like a hack, because of the necessary error surpression. But
perhaps it will help you for now.


JW




Report this thread to moderator Post Follow-up to this message
Old Post
Janwillem Borleffs
12-21-04 08:55 AM


Re: howto? parse multiple xml strings with domxml
Janwillem Borleffs wrote:
> This would assign the XML contents to the fifth argument, setting it
> as an XSL parameter.
>

That would be the sixth argument, of course...

JW




Report this thread to moderator Post Follow-up to this message
Old Post
Janwillem Borleffs
12-21-04 08:55 AM


Re: howto? parse multiple xml strings with domxml
bc wrote:
> Hello Janwillem! Thanks for your reply. I tried out your suggestion
> and some variations on it, but without success. document() cannot
> interprete a parameter as XML, it seems.
>

If you would follow my suggestion exactly, you will see that it is possible
(it worked for me).

> Is it conceptually wrong to parse 10 XML strings with one XSL file?
> How do other XML- sites manage this?
>

There is nothing wrong with this approach. Most XML-based systems work like
this, because you will then have to maintain only one XSLT file and the XML
files are maintained by the data they contain.

> The 10 XML strings are returned from a custom PHP function that
> communicates with an external PostGres DB. Should I stick these XML
> strings together? If yes, I'll need to adapt every XSL file... which
> is a huge job.
>

You won't have to stick the XML strings together, but will have to adapt the
XSL file(s) to support the <xsl:param /> scheme.

If you want, you can send the files to my email address (not to this
newsgroup), after which I probably will be able to help you further.

Note that when the attachment is larger than 500kB, I won't be able to
receive it. Put it on a place where I can download it from instead.


JW




Report this thread to moderator Post Follow-up to this message
Old Post
Janwillem Borleffs
12-21-04 08:55 AM


Re: howto? parse multiple xml strings with domxml
Hello Janwillem! Thanks for your reply. I tried out your suggestion
and some variations on it, but without success. document() cannot
interprete a parameter as XML, it seems.

I'm totally clueless...

Is it conceptually wrong to parse 10 XML strings with one XSL file?
How do other XML- sites manage this?

The 10 XML strings are returned from a custom PHP function that
communicates with an external PostGres DB. Should I stick these XML
strings together? If yes, I'll need to adapt every XSL file... which
is a huge job.

Working with XML seems a big hassle to me. More work, and always
relying on external libraries, less support... I wish I could just
connect straight to the DB.

Anyway, thnx for you help,

Barton


On Thu, 16 Dec 2004 18:44:22 +0100, "Janwillem Borleffs"
<jw@jwscripts.com> wrote:

>Janwillem Borleffs wrote: 
>
>There must be a better way, but until I have found one, the following
>workaround could do the trick for now:
>
>In the code mentioned before, replace the following sections:
>
>Change:
>
>// Start the transformation
>$processed = $xsltproc->transformToXML($xml);
>
>Into:
>
>// Start the transformation
>$processed = @$xsltproc->transformToXML($xml);
>
>Now the call would be as follows:
>
>$html = xslt_process(
>       $xsltproc,
>       'arg:/_xml',
>       'arg:/_xsl',
>       null,
>       $arguments,
>       array('document'=>$arguments['/_xml'])
> );
>
>This would assign the XML contents to the fifth argument, setting it as an
>XSL parameter.
>
>In the XSLT, you should then able to do the following:
>
>    <xsl:param name="document" />
>    <xsl:template match="/">
>
>    <xsl:for-each select="document($document)/content">
>       ....
>    </xsl:for-each>
>
>This is more like a hack, because of the necessary error surpression. But
>perhaps it will help you for now.
>
>
>JW
>
>


Report this thread to moderator Post Follow-up to this message
Old Post
bc
12-21-04 01:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:01 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.