Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > how to create a valid xml file with php and mysql

Reply
Thread Tools

how to create a valid xml file with php and mysql

 
 
Kentor
Guest
Posts: n/a
 
      05-29-2006
I have some info that im grabbing from a mysql database with php and i
want to make an xml file but i know that i need to be carefull with the
& sign and so on... how can i clean the data coming from the db to have
a valid xml file?

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      05-29-2006


Kentor wrote:

> I have some info that im grabbing from a mysql database with php and i
> want to make an xml file but i know that i need to be carefull with the
> & sign and so on... how can i clean the data coming from the db to have
> a valid xml file?


The latest 5.1.something PHP release has XmlWriter to generate XML:
<www.php.net/XMLWriter>
--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Kentor
Guest
Posts: n/a
 
      05-29-2006
thanx... it's pretty complex... =/

 
Reply With Quote
 
Kentor
Guest
Posts: n/a
 
      05-30-2006
anything else =/

 
Reply With Quote
 
Tuomas Rannikko
Guest
Posts: n/a
 
      05-30-2006
Kentor wrote:
> anything else =/
>


I think you should go with the XMLWriter

However

I guess, if you're just putting some character data in semi-fixed tags
(rather than trying to generate the document structure from the db) you
could maybe escape the character data with something like this:


$original = "this&that ]]><foo";
$pattern = array("&", "<", "]]>");
$replacement = array("&amp;", "&lt;", "]]&gt;");
$escaped = preg_replace($pattern, $replacement, $original);

I didn't test this, and whether this works is up to the implementation
of preg_replace()...

Note if you're planning to put strings into attribute values the ' and "
characters should be escaped as well. (With &apos; and &quot; respectively.)

There is also a caveat; the XML 1.0 spec doesn't allow for some
"special" characters and therefore it is possible that the document is
still not well-formed even if the code does work as I intended. If
you're afraid of encountering characters not allowed to occur in XML 1.0
you should declare the XML version to be 1.1, which allows for almost
all unicode characters. That means you put the string

<?xml version="1.1"?>

first in the document.

--

- Tuomas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
PHP MySQL Web Development - Why Do You Need a PHP & MySQL ... neha shena Python 1 10-29-2010 04:54 AM
FREE SEMINAR on PHP Web Development in Lahore and Rawalpindi, Itcovers PHP, MySQL, AJAX & Zend Certification EVS MCSE 0 05-31-2010 01:13 PM
PHP Training Institute In Delhi, Live Projects on PHP. Short TermPHP Courses, PHP Scripts, PHP Training with Live Projects. Rajive Narain Java 0 09-18-2009 10:47 AM



Advertisments