473,395 Members | 1,622 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,395 software developers and data experts.

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 21327
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
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
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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.