How to append XML file to another XML file - php

I'm trying to create an xml-based template system. The idea is to return my views as xml files (xhtml) and then append them to specific nodes in a template xml file. The template xml is then transformed with xslt.
My question is: how do I insert these xml files into the template xml file?

See DOMDocument::importNode and DOMNode::appendChild.

Related

wkhtmltopdf style table of contents

I'm wondering how i can go about reducing the font size on the generated table of contents.
I've read and reread their documentation here: https://wkhtmltopdf.org/usage/wkhtmltopdf.txt
The bit i'm confused on is:
The generated XML document can be viewed by dumping it to a file using the
--dump-outline switch. For example:
wkhtmltopdf --dump-outline toc.xml http://qt-project.org/doc/qt-4.8/qstring.html qstring.pdf
I'm having difficulty understanding how to translate to my own project, and what do they mean by this part of the command:
http://qt-project.org/doc/qt-4.8/qstring.html qstring.pdf
If you want to change the default table of content (HTML and / or CSS styles), you can use the xsl-style-sheet parameter to specify a custom XLS stylesheet.
In your custom XLS you can add any HTML tag you need.
You can find an example of the default XLS file here. For your information, le XLS is generated from the tocstylesheet.cc file (see here).

How can I use a .dot Template on .docx generation in PHP

I'm currently writing a docx generator in PHP. It creates tables, images, paragraphs e.g. and saves everything in the correct structure to a .zip (.docx). Now i need to include some macros into that .docx.
I have the macros in a .dot Template on a network drive, which is accessible for my .docx documents. How can I link that Template to my .docx-File?
Important:
I need an approach to link the .dot file in the source of the .docx file. The macros should be automatically added in every .docx my Web-Tool creates for users.
Thanks for every advice
When adding a macro to a docm file, it results in three new files:
/word/_rels/vbaProject.bin.rels
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.microsoft.com/office/2006/relationships/wordVbaData" Target="vbaData.xml"/></Relationships>
and vbAData.bin
and vbaProject.bin
I suggest you to create a file with a macro to see what's in there.
I would like to add that there's an easy way to create docx templates: Using a library I have created and I actively maintain:
https://github.com/edi9999/docxtemplater
Hope that helps

php file to pdf

I was converting a HTML file to PDF using dompdf. I managed to get the desired result but a problem arose, the HTML file needs to be converted to PHP because it will receive data from a form (from another file)!
The dompdf in this case doesn't work and it not shows the result of what was written in the form.
I think what you search is a template Engine to replace values in a HTML file.
There are some Engines like Smarty, TWIG.
You can parse your HTML file and with the HTML return you can create your PDF file.
Perhaps its a bit oversized for your case but you could build your own short engine and parse your HTML file and replace your specified Tags with the form values.
You can create your html file automaticaly in temp. After request to your php file, your file generates automaticaly a .html file (in temp), then create your pdf from this file.

HTTP Headers Information to show XML file

I want to show XML file on my page, I have set the header header('Content-Type: application/xml')also tried for header(application/rss+xml),
but my URL can not show the page in XML format but in View Page Source it created the XML file
URL- http://submitsitelink.com/rss.php?p=d
Can you please help me ?
Thanks
Google Chrome can neither read RSS nor beautify XML natively. You have to find and install an extension:
RSS Subscription Extension
XML Tree
It sounds like you want to style the output of your XML - one method of doing this is via XSL technologies. You can also add CSS stylesheets to XML documents by adding something akin to the following near the top of your XML document.
<?xml-stylesheet href="common.css"?>
As far as I know you cannot do this with HTTP headers, only by modifying the XML document itself.

PHP in XML file (or PHP file as XML one)

I have this code (part of bigger script):
flashvars.xmlSource = "datasource.xml";
datasource.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<Object>
<Contents>
<Source="address" Title="title"></Source>
<Description><h1>New hot Features</h1><p>The all new Piecemaker comes with lots of new features, making it even more slick.</p><p>Just to mention a few - you can now specify unlimited transition styles, include your own SWF and Video files, add hyperlinks to images and info texts with all special characters.</p><p>We also impoved the navigation and the animation with animated shadows and pixel-perfect transitions.</p></Description>
(...)
</Contents>
</Object>
I want to generate datasource.xml dynamically using foreach loop.
I've just changed the file extension to .php but this is not that easy ;)
Any ideas?
Funny or not, but try this one:
leave your file extension to be "xml"
where you wrote (...) write <? PHP CODE HERE ?>
So handle it as if it would be some html file. What I mean is:
<?xml version="1.0" encoding="utf-8"?>
<Object>
<Contents>
<Source="address" Title="title"></Source>
<Description><h1>New hot Features</h1><p>The all new Piecemaker comes with lots of new features, making it even more slick.</p><p>Just to mention a few - you can now specify unlimited transition styles, include your own SWF and Video files, add hyperlinks to images and info texts with all special characters.</p><p>We also impoved the navigation and the animation with animated shadows and pixel-perfect transitions.</p></Description>
<? create php loop here ?>
</Contents>
</Object>
Also note
this line
<Source="address" Title="title"></Source>
might be wrong (you assigned some value to the tagname), try
<Source name="address" Title="title"></Source>
or something like that.
As I see generating xml file with php could be done in this way - for example you'll create file datasource.xml which will be not a static xml file but xml with php code included with contents like
<?php //php code to generate any xml code as Text
// it can be whatever you need to generate
// for example
$content="<h1>New hot Features</h1><p>The all new Piecemaker comes with lots of new features, making it even more slick.</p><p>Just to mention a few - you can now specify unlimited transition styles, include your own SWF and Video files, add hyperlinks to images and info texts with all special characters.</p><p>We also impoved the navigation and the animation with animated shadows and pixel-perfect transitions.</p>";
$output="<Description>".$content."</Description>";
header('Content-type: application/xml');// this is most important php command which says that all output text is XML it must be called before any line of xml will be printed.
// So you need at first generate XML as text then call this command and echo contents of your xml file.
?>
<?xml version="1.0" encoding="utf-8"?>
<Object>
<Contents>
<Source name="address" Title="title"></Source>
<? echo $output; ?>
</Contents>
</Object>
In order to allow php to execute php code inside XML file we need to add some directives to apache host configuration file. In my case I added
<IfModule mod_php5.c>
<FilesMatch "\.xml$">
SetHandler application/x-httpd-php
</FilesMatch>
inside my virtual host configuration file, or you can place this command inside .htaccess file in your directory if Override of this param is allowed in your host configuration.
And about xml- to make sure it's ok you can use http://validator.w3.org/ or http://www.w3schools.com/xml/xml_validator.asp to validate xml generated by your script.
Does this XML need to be a stored file somewhere on the server, or can you just pass it a string formatted like the XML you mentioned. You could write a function that generates the XML you're looking for and returns it, based on input and then call that like
function generateXML($input){
$xml = '<?xml version="1.0" encoding="utf-8"?><Object><Contents>
<Source="address" Title="title"></Source><Whateverelse>' . $input;
$xml .= '</Whateverelse></Contents></Object>';
return $xml;}
flashvars.xmlSource = generateXML("This is whatever else");
If you need to actually generate and store a well formed XML document, or if your XML is fairly complex and you need to generate an object rather than just using a string, you can utilize one of the PHP libraries to do this like http://php.net/manual/en/book.simplexml.php

Categories