473,509 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

read and edit xml with PHP

Hi all,
Thanks in advance for any help that you can give. I'm trying to write
some php that will read in some xml and then allow me to modify the tag

and write back out to xml.
In the following example, I want to read in 'text_for_paragraph_1',
then allow it to be viewed, edited, and saved back to the xml... I
have absolutely no clue even where to start...any help at all would be
more than appreciated!!
thanks,
john
<?xml version="1.0" standalone="yes"?>
<module name="GS02" course="Demo">
<page>
<Name><![CDATA[ c0300010 (Ref Num 772) ]]></Name>

<Screen_Type><![CDATA[Text_wit*h_Image]]></Screen_Type>
<Description><![CDATA[ &nbsp; ]]></Description>
<Script>
<Text_for_Paragraph_1><![CDATA*[ Welcome to
lesson 1 of module 2.
&nbsp; In this lesson, you will learn about the emerging trends in the
IT marketplace. ]]></Text_for_Paragraph_1>
</Script>
</page>
</module

Jul 17 '05 #1
3 21331
John Gauger wrote:
Hi all,
Thanks in advance for any help that you can give. I'm trying to write some php that will read in some xml and then allow me to modify the tag
and write back out to xml.
In the following example, I want to read in 'text_for_paragraph_1',
then allow it to be viewed, edited, and saved back to the xml... I
have absolutely no clue even where to start...any help at all would be more than appreciated!!
thanks,
john
<?xml version="1.0" standalone="yes"?>
<module name="GS02" course="Demo">
<page>
<Name><![CDATA[ c0300010 (Ref Num 772) ]]></Name>

<Screen_Type><![CDATA[Text_wit*h_Image]]></Screen_Type>
<Description><![CDATA[ &nbsp; ]]></Description>
<Script>
<Text_for_Paragraph_1><![CDATA*[ Welcome to
lesson 1 of module 2.
&nbsp; In this lesson, you will learn about the emerging trends in the IT marketplace. ]]></Text_for_Paragraph_1>
</Script>
</page>
</module


Some possible approaches (visit the PHP manual at http://php.net/manual
for more details on these functions, etc.):

* preg_match() and preg_replace(). Devise a regular expression that
gives a hit on <Text_for_Paragraph_1>...</Text_for_Paragraph_1>.

* Use an XSLT transform (see the PHP XSLT functions).

* Load the whole script in using the XML DOM functions, and the find
and replace the contents of the relevant element.

* Save the XML file as some sort of template, with something like
{PARAGRAPH_TEXT} in the right place. Then do a preg_replace() on this.
P.S. Are you aware that you don't have to escape *all* character data
with <![CDATA[ ... ]]>? This is only necessary if you want to express
data that would otherwise look like XML.

--
Oli

Jul 17 '05 #2
Hi John

There's probably more than one library made for PHP that takes care of
XML reading/writing, one is below.

http://phpxmlclasses.sourceforge.net/

Jul 17 '05 #3
http://minixml.psychogenic.com/

seems to be even better.

Jul 17 '05 #4

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

Similar topics

3
1994
by: Konan | last post by:
Pardon the simple question, but I have just begun to learn PHP. So far so good - all the examples in my books actually work. One thing that none of them address is how to read a file of strings...
7
12643
by: Graham Taylor | last post by:
I've tried posting this in the 'microsoft.public.access' but I will post it here also, as I think it might be the webserver which is causing my problem. --------- I have an Access 2003 database...
1
10067
by: libbythomas | last post by:
I created an Access 2000 form from a query. But I cannot edit it. I can flip through the records. If I create a table from the query (maketable) and then create the form from the table, it is...
1
3364
by: ywchan | last post by:
I would like to make some of the rows in the datagrid read only according to certain condition. How can I make some of the rows editable while others read only in a datagrid? Thanks!
2
1810
by: Vish | last post by:
Hi, I amplanning on having a rea-only and edit states for my form. But it do not want my form and its controls to look different or disabled. I am planning on having a edit button that brings...
4
2645
by: CrimeMaster | last post by:
HI I have an Exe file when it runs ,there are just two controls on the window.One is a ListBox and another is a Multi line Rich Edit control.When i click on an item in the list some text is...
3
1851
by: jao.sanien | last post by:
Hi I have a access file that need to be made to read only. And the file should be password protected if I want to edit something. So those who doesn't have the password can only read. I don't...
0
1385
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi all, I have a column that the user is only allowed to edit if s/he added the row. I set read-only = true for this column when I load the grid. I allow the user to add a row by clicking a...
9
5742
hsriat
by: hsriat | last post by:
I have to toggle the name of a hyperlink from Edit to Save and vice-versa on click event of the same hyperlink. This is the HTML part, <input class="text" id="ix1" type=text></input> <a...
0
7342
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
7410
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
7505
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
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.