473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Generated XML with PHP

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
<<<<<<<<<<<<<<<<<<<<<<<
Jul 20 '05 #1
2 2001


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/

Jul 20 '05 #2
Martin Honnen <ma*******@yahoo.de> wrote in message news:<40********@olaf.komtel.net>...
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.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Irmen de Jong | last post by:
Hello, I don't understand why the following doesn't work. What I want to do is dynamically import some generated Python code and I'm doing this using compile and exec'ing it in the dict of a new...
3
by: Headless | last post by:
Should linking generated content work? Example: span:before{content:"foobar"} <a href="foobar.htm"><span></span></a> I stumbled across this bit in the CSS2 spec: >Generated content does...
6
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
1
by: Robert Stearns | last post by:
I have two related questions. Why did I have to: SET INTEGRITY FOR is3.animals OFF; before doing: alter table is3.animals add column pseudo_id generated always as (coalesce(regnum,...
2
by: msnews.microsoft.com | last post by:
AOA I am using httpwebrequst and httwebresponse classes in order to execute an html page. The html generaed is then emailed. My problem is that I am calling the GenerateHtmlText() method which is...
1
by: Peter McEvoy | last post by:
Hi all, another question related to Schema and WSDL... I'd like to have a bit more control over the WSDL that is generated for my ..asmx. In particular, I'd like to override the generated WSDL...
17
by: Darek | last post by:
Hi, I have a table, something similar to: create table my_table ( id char(32) not null primary key, num integer not null, code varchar(2) not null, name varchar(60) not null,
4
by: Fabio | last post by:
An ASP.NET 2.0 web site contains a web form and a web service. The web form consumes the web service. There is a Book class in the App_Code folder. The web service exposes a method that returns a...
1
by: Frank Swarbrick | last post by:
We're trying to take advantage of the new ROW CHANGE TIMESTAMP option. Here is a simple table: CREATE TABLE "ACCTASGN"."NUMBER_STATUS" ( "STATUS_CODE" CHAR(1) NOT NULL , "STATUS_DESCRIPTION"...
4
by: bob_jenkins | last post by:
C# allows code to be generated, but the generated code is in its own assembly. Is there a way for that generated code to access internal classes in the assembly that produced it? To have the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.