473,327 Members | 2,025 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,327 software developers and data experts.

I have an XML file and want to insert from php4.

XML:
Expand|Select|Wrap|Line Numbers
  1. <shops> 
  2. <fashion> 
  3. <shirt> 
  4. <product> 
  5. <soort>A</soort> 
  6. <link>B</link> 
  7. </product> 
  8. </shirt> 
  9. <pants> 
  10. <product> 
  11. <soort>E</soort> 
  12. <link>F</link> 
  13. </product> 
  14. </pants> 
  15. </fashion> 
  16. </shops> 


PHP4:
Expand|Select|Wrap|Line Numbers
  1. $xml = domxml_open_file('shop.xml'); 
  2.  
  3. $newproduct = $xml->fashion->shirt->create_element("product"); 
  4. $newproduct->append_child("soort","aaaaa"); 
  5. $newproduct->append_child("link","bbbbb"); 
  6. $a = $xml->append_child($newproduct); 
  7. $xml->dump_file('shop.xml'); 


The file is written, but nothing has been changed. Why?
Sep 6 '10 #1

✓ answered by Dormilich

no, but in JavaScript you work all the time with the DOM. what I wanted to say – it works like in JavaScript.

e.g. (see the similarities)
Expand|Select|Wrap|Line Numbers
  1. // JavaScript
  2. var p = document.createElement("p");
  3. document.getElementById("test").appendChild(p);
Expand|Select|Wrap|Line Numbers
  1. // PHP (untested)
  2. $p = $xml->create_element("p");
  3. $xml->get_element_by_id("test")->append_child($p);

11 1783
Dormilich
8,658 Expert Mod 8TB
are you sure this works? this is not SimpleXML.
Expand|Select|Wrap|Line Numbers
  1. $newproduct = $xml->fashion->shirt->create_element("product");
Sep 6 '10 #2
So this is where the miswriting starts?
Sep 6 '10 #3
Dormilich
8,658 Expert Mod 8TB
I’m not too familiar with DOM in PHP 4, but that’s definitely not DOM syntax. this wouldn’t even work in JavaScript.
Sep 7 '10 #4
First, thank you for trying to help me.

Now i also tried this:

Expand|Select|Wrap|Line Numbers
  1. $newproduct = $xml->get_elements_by_tagname("shirt");
and this isn't working also.
Sep 7 '10 #5
Dormilich
8,658 Expert Mod 8TB
not working in what regard? createElement() is a method of the Document, not of a Node*.

additionally, if you’r not sure, whether the method call succeeds, print it out with var_dump().

* - fyi, I’m using the spelling as defined in the specs (which slightly differs from the spelling used for PHP 4).
Sep 7 '10 #6
OK, thanks i did not know that. But how do i get further in the tree for inserting the product part?
Sep 7 '10 #7
Dormilich
8,658 Expert Mod 8TB
how familiar are you with JavaScript?
Sep 7 '10 #8
wel, i can write xml with javascript for output to the site and getting al the tree elements. But i dont know how to save the xml in javascript. But i can look it up. You think thats a better solution for this?
Sep 7 '10 #9
Dormilich
8,658 Expert Mod 8TB
no, but in JavaScript you work all the time with the DOM. what I wanted to say – it works like in JavaScript.

e.g. (see the similarities)
Expand|Select|Wrap|Line Numbers
  1. // JavaScript
  2. var p = document.createElement("p");
  3. document.getElementById("test").appendChild(p);
Expand|Select|Wrap|Line Numbers
  1. // PHP (untested)
  2. $p = $xml->create_element("p");
  3. $xml->get_element_by_id("test")->append_child($p);
Sep 7 '10 #10
OK! i see the simularity there. Thank you so much i think this is it.
Sep 7 '10 #11
Dormilich
8,658 Expert Mod 8TB
that’s the good part of the DOM, it’s used the same on every implementing system.
Sep 7 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Red2 | last post by:
Hi All, I am receiving a flat file data feed from another system. This is comming in every 10 minutes and is going to need to be a high permormance system. The file will contain all the data...
4
by: Brian Parker | last post by:
Here's a snippet of code I have: ============================================== DataSet ds = new DataSet(); string strXMLFileName = Path.GetTempFileName(); StreamWriter sw = File.AppendText(...
2
by: Dave | last post by:
I have a program that unzips a file and processes the extracted file. This works fine on my local machine but when I run it on a Win 2003 server I receive the error, "Windows has blocked the...
9
by: anachronic_individual | last post by:
Hi all, Is there a standard library function to insert an array of characters at a particular point in a text stream without overwriting the existing content, such that the following data in...
1
by: nothing1 | last post by:
I dont really know much about Perl but what i would like to do is name a file after a folder in my server and in that file contain whats in the text file. It works fine so far but what I would really...
1
by: umakanttiwari | last post by:
how we raed .dbf file and insert data in oracle in java
3
by: jmark | last post by:
I am currently running php 4.4.7 in windows xp and apache 2. If I enter php in command line. I get the following error The application has failed to start because php5ts.dll was not found" I...
5
by: Pelle | last post by:
Hello programmers, I have a toolbox that's often working with a FILE * to access files and the lot. Recently, need has arisen to look at the filename of a file when I only have a FILE *. I...
1
by: sydmil | last post by:
Hello, I am relatively new to VB6 and I was wondering if anyone could show me an example of a VB6 code to do the following: Open text file (which is a column of numbers) in excel - comma...
29
by: FreshRob | last post by:
I have been trying to fix this issue the whole of today and have gotten no where. I am developing a new website, and wanted it to display a webpage in lightbox and have an external page added to the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.