Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Generated XML with PHP

Reply
Thread Tools

Generated XML with PHP

 
 
Joel Witherspoon
Guest
Posts: n/a
 
      04-11-2004
I'm generating an xml file using PHP DOMXML . I'm able to create and
edit the file fine, however the formatting of my file is off. Instead
of being the standard xml:
<?xml version="1.0">
<root>
<element>
</element>
</root>

I am getting:
<?xml version="1.0">
<root>
<element></element></root>

Here is the code:

PHP:
$tdindex = time(); //creates unix time var for indexing
$doc = domxml_new_doc('1.0');
$root = $doc->add_root('categories');
$category = $doc->create_element('category');
$category = $root->append_child($category);

$category->set_attribute('index',$tdindex);
$cattext = $doc->create_text_node($cat);
$cattext = $category->append_child($cattext);
$description =
$doc->create_element('description');
$description =
$category->append_child($description);
$desctext = $doc->create_text_node($desc);
$desctext =
$description->append_child($desctext);



//create file if it doesn't exist and dump memory into it
$filename = realpath('categories.xml');
$doc->dump_file($filename, false, true);


Is there an method in DOMXML that formats the file? I thought
dump_file or dump_mem handled it.
Any help is appreciated.

__________________
>>>>>>>>>>>>>>>>>>>>>>>

Joel
<<<<<<<<<<<<<<<<<<<<<<<
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-11-2004


Joel Witherspoon wrote:

> I'm generating an xml file using PHP DOMXML . I'm able to create and
> edit the file fine, however the formatting of my file is off. Instead
> of being the standard xml:
> <?xml version="1.0">
> <root>
> <element>
> </element>
> </root>
>
> I am getting:
> <?xml version="1.0">
> <root>
> <element></element></root>
>
> Here is the code:
>
> PHP:
> $tdindex = time(); //creates unix time var for indexing
> $doc = domxml_new_doc('1.0');
> $root = $doc->add_root('categories');


add_root is deprecated, consider using create_element and then append_child.

> $category = $doc->create_element('category');
> $category = $root->append_child($category);
>
> $category->set_attribute('index',$tdindex);
> $cattext = $doc->create_text_node($cat);
> $cattext = $category->append_child($cattext);
> $description =
> $doc->create_element('description');
> $description =
> $category->append_child($description);
> $desctext = $doc->create_text_node($desc);
> $desctext =
> $description->append_child($desctext);
>
>
>
> //create file if it doesn't exist and dump memory into it
> $filename = realpath('categories.xml');
> $doc->dump_file($filename, false, true);
>
>
> Is there an method in DOMXML that formats the file? I thought
> dump_file or dump_mem handled it.



When I try the following with PHP 4.3.3 on Windows

<?php
$xmlDocument = domxml_new_doc('1.0');
$documentElement = $xmlDocument->create_element('gods');
$xmlDocument->append_child($documentElement);
$god = $xmlDocument->create_element('god');
$name = $xmlDocument->create_element('name');
$name->append_child($xmlDocument->create_text_node('Kibo'));
$god->append_child($name);
$documentElement->append_child($god);
$xmlDocument->dump_file('test20040411.xml', FALSE, TRUE);
?>
<p>
<a href="test20040411.xml">test XML file</a>
</p>

then the resulting file looks fine to me

<?xml version="1.0"?>
<gods>
<god>
<name>Kibo</name>
</god>
</gods>

What version of PHP are you using?
--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
 
Joel Witherspoon
Guest
Posts: n/a
 
      04-11-2004
Martin Honnen <(E-Mail Removed)> wrote in message news:<4079205a$(E-Mail Removed)>...
> Joel Witherspoon wrote:
>
> > I'm generating an xml file using PHP DOMXML . I'm able to create and
> > edit the file fine, however the formatting of my file is off. Instead
> > of being the standard xml:
> > <?xml version="1.0">
> > <root>
> > <element>
> > </element>
> > </root>
> >
> > I am getting:
> > <?xml version="1.0">
> > <root>
> > <element></element></root>
> >
> > Here is the code:
> >
> > PHP:
> > $tdindex = time(); //creates unix time var for indexing
> > $doc = domxml_new_doc('1.0');
> > $root = $doc->add_root('categories');

>
> add_root is deprecated, consider using create_element and then append_child.
>
> > $category = $doc->create_element('category');
> > $category = $root->append_child($category);
> >
> > $category->set_attribute('index',$tdindex);
> > $cattext = $doc->create_text_node($cat);
> > $cattext = $category->append_child($cattext);
> > $description =
> > $doc->create_element('description');
> > $description =
> > $category->append_child($description);
> > $desctext = $doc->create_text_node($desc);
> > $desctext =
> > $description->append_child($desctext);
> >
> >
> >
> > //create file if it doesn't exist and dump memory into it
> > $filename = realpath('categories.xml');
> > $doc->dump_file($filename, false, true);
> >
> >
> > Is there an method in DOMXML that formats the file? I thought
> > dump_file or dump_mem handled it.

>
>
> When I try the following with PHP 4.3.3 on Windows
>
> <?php
> $xmlDocument = domxml_new_doc('1.0');
> $documentElement = $xmlDocument->create_element('gods');
> $xmlDocument->append_child($documentElement);
> $god = $xmlDocument->create_element('god');
> $name = $xmlDocument->create_element('name');
> $name->append_child($xmlDocument->create_text_node('Kibo'));
> $god->append_child($name);
> $documentElement->append_child($god);
> $xmlDocument->dump_file('test20040411.xml', FALSE, TRUE);
> ?>
> <p>
> <a href="test20040411.xml">test XML file</a>
> </p>
>
> then the resulting file looks fine to me
>
> <?xml version="1.0"?>
> <gods>
> <god>
> <name>Kibo</name>
> </god>
> </gods>
>
> What version of PHP are you using?


I'm using 4.3.2 on Win2K with Apache 2.0.47. Fixed it. The problem was
$doc->add_root();. Thanks for your time.
 
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
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
php-generated email not formatting on a mac Paul Furman HTML 13 06-10-2009 12:29 AM
IE not showing PHP-generated images, but Firefox does. ur.solame@yahoo.com HTML 29 04-14-2008 02:04 PM
Writing a PHP and Javascript generated page to a PHP variable... jonnyblazed@gmail.com Javascript 3 09-04-2006 12:45 PM
php generated html needs simple javascript function, yet my javascriptsux mk Javascript 5 07-28-2006 07:21 AM



Advertisments