Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I dump the xml I retrieve using PHP FUNCTION DOMXPATH::QUERY?

Posted on 2011-03-24
8
Medium Priority
?
361 Views
Last Modified: 2012-06-27
Hi,

I am trying to extract xml from a file and pass it to the xslt parser but its not working. How do I get the attached code to work?

I need to extract the products node and its children to pass to the stylesheet.

Thanks
<config>
<top40>
<products>
<product>
 ...
</product>
</products>
</config>

Open in new window

<?php
$doc = new DOMDocument();
$xsl = new XSLTProcessor();

$doc->load('xsl/products.xsl');
$xsl->importStyleSheet($doc);
$doc->load('xml/config.xml');
$xpath = new DOMXPath($doc);
$p = $doc->getElementsByTagName('top40')->item(0);
$x = $xpath->query('*',$p);

$data = $xsl->transformToXML($x);
echo $data;
?>

Open in new window

0
Comment
Question by:dilithiumtoys_dot_com
  • 4
  • 4
8 Comments
 

Author Comment

by:dilithiumtoys_dot_com
ID: 35212620
I get this error

Warning: XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]: Invalid Document
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35213980
It doesn't like your XML. I notice that your sample data does not start with the usual header

<?xml version="1.0"?>
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35213988
Also, is there a reason why you are using DOM rather than SimpleXML? Are you on PHP4?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:dilithiumtoys_dot_com
ID: 35215042
I am generating the XML from SQL Server, I am sure I can return a declaration, if I can find out the method. May I transform documents to html using SimpleXML? I am using PHP 5.
0
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 1500 total points
ID: 35215072
SImpleXML is no use at transforming documents, but is only available in PHP5, not PHP4, thus my question about it. It is also very simple to use, thus its name.......

Try adding the <?xml header to the generated code and attempt your re-import.
0
 

Author Comment

by:dilithiumtoys_dot_com
ID: 35221948
That did not work.

What worked was a mixture of simplexml extraction and saving as xml being passed to DOM and XSLTPROCESSOR.

0
 

Author Closing Comment

by:dilithiumtoys_dot_com
ID: 35221950
Partially correct. I figured out my own answer
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35230484
I didn't want to suggest SimpleXML as it seems that those using DOM either don't like SimpleXML or have requirements beyond its needs. Still I'm glad that you got it sorted out.

Cheers!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question