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

modify xml file php script

how to create script that modify xml file

sample xml file:

<root>
<parent name="a" id="1">
<child name="a.a" id="1.1" />
<child name="a.b" id="1.2" />
<child name="a.c" id="1.3" />
</parent>
<parent name="b" id="2">
<child name="b.a" id="2.1" />
</parent>
<parent name="c" id="3">
<child name="c.a" id="3.1" />
<child name="c.b" id="3.2" />
</parent>
</root>

php script should be able to modify the xml file. it should be able to
insert a parent element say between parent A and parent B. the id of
the new parent element should be parent B with its child respectively.
the parent elements below the new element should adjust the ids. in the
example above, parent B id should be 3 and its child id should be 3.1.
same goes to parent C and its childs.
result would be:
<root>
<parent name="a" id="1">
<child name="a.a" id="1.1" />
<child name="a.b" id="1.2" />
<child name="a.c" id="1.3" />
</parent>
<parent name="newparent" id="2">
<child name="newparent.a" id="2.1" />
<child name="newparent.b" id="2.2" />
</parent>
<parent name="b" id="3">
<child name="b.a" id="3.1" />
</parent>
<parent name="c" id="4">
<child name="c.a" id="4.1" />
<child name="c.b" id="4.2" />
</parent>
</root>

any comments on this...

Aug 31 '05 #1
4 8713
Hi,

DOM should be your friend, for Documentation read this:

http://de2.php.net/manual/en/ref.dom.php

Have fun ..

Wolfgang

jp**********@gmail.com wrote:
how to create script that modify xml file

sample xml file:

<root>
<parent name="a" id="1">
<child name="a.a" id="1.1" />
<child name="a.b" id="1.2" />
<child name="a.c" id="1.3" />
</parent>
<parent name="b" id="2">
<child name="b.a" id="2.1" />
</parent>
<parent name="c" id="3">
<child name="c.a" id="3.1" />
<child name="c.b" id="3.2" />
</parent>
</root>

php script should be able to modify the xml file. it should be able to
insert a parent element say between parent A and parent B. the id of
the new parent element should be parent B with its child respectively.
the parent elements below the new element should adjust the ids. in the
example above, parent B id should be 3 and its child id should be 3.1.
same goes to parent C and its childs.
result would be:
<root>
<parent name="a" id="1">
<child name="a.a" id="1.1" />
<child name="a.b" id="1.2" />
<child name="a.c" id="1.3" />
</parent>
<parent name="newparent" id="2">
<child name="newparent.a" id="2.1" />
<child name="newparent.b" id="2.2" />
</parent>
<parent name="b" id="3">
<child name="b.a" id="3.1" />
</parent>
<parent name="c" id="4">
<child name="c.a" id="4.1" />
<child name="c.b" id="4.2" />
</parent>
</root>

any comments on this...

Aug 31 '05 #2
actually, im more concern about the logic behind of the script. how do
you make the id update in cascading manner. anyway, thanks for the reply

Aug 31 '05 #3
Hm ..

this maybe an answer but there could be better solutions that my one :-)

<?php

// ... fetch your id with DOM

$id_array = explode(".", $id);

// id[0] == first number of ID
// id[1] == second number of ID
// count up second one

id[1]++;

// connect id that you have back x.x

$id = implode(".",$id[0].$id[1]);

// write id back to XML (using DOM) ...

?>

dem0o8 wrote:
actually, im more concern about the logic behind of the script. how do
you make the id update in cascading manner. anyway, thanks for the reply

Aug 31 '05 #4
i guess that will work for me though i haven't tried it yet. thanks a
lot wolfgang.

Aug 31 '05 #5

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

Similar topics

4
by: Sherman Willden | last post by:
I am trying to use Perl's XML::Twig to modify a version number in an XML document. At the very end of this posting is an excerpt from the xml document. Just before the xml excerpt is the Perl code...
2
by: Veeven | last post by:
Hi, Suppose I have an XML file like this on the web, say, http://www.example.com/list.xml <?xml version='1.0'?> <list> <item id='itm01'> <name>Item 1</name> <desc>This is item 1</desc>
2
by: Got2Go | last post by:
Hello, I am trying to come up with a function that will search the source of the page for a specific string. If that string is found, then have it modify specific tags inside of a table and...
1
by: Luca Giannoni | last post by:
Hello everybody, I have this problem: I have a file javascript xxx.js that I include in my asp page as <SCRIPT SRC="scripts/xxx.js"> It's possible to modify content of xxx.js at runtime... I...
16
by: Philippe C. Martin | last post by:
Hi, I am trying to change the data in a form field from python. The following code does not crash but has no effect as if "form" is just a copy of the original html form. Must I recreate the...
3
by: DC Gringo | last post by:
Hi, I'm trying to use a custom action to modify a database (rather than create one) using the VS.NET '03's help example called "Custom Action to Create Database During Installation". I've made...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
2
by: Benjamin Rutt | last post by:
I often execute a long-running python script which is a "driver" for my application; it may run for several hours on a large input. Under CPython, is it safe for me to modify the Python script...
5
by: kidders | last post by:
Below is a script i need to modify to work and its driving me nuts. Essentially it fades the content of an array. The original script specified the object name, I tried to modify it to allow an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.