472,371 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 1960


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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.