Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

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=3D"1.0" standalone=3D"yes"?>
<module name=3D"GS02" course=3D"Demo">
<page>
<Name><![CDATA[ c0300010 (Ref Num 772) ]]></Name>

<Screen_Type><![CDATA[Text_wit=ADh_Image]]></Screen_Type>
<Description><![CDATA[   ]]></Description>
<Script>
<Text_for_Paragraph_1><![CDATA=AD[ Welcome to
lesson 1 of module 2.
  In this lesson, you will learn about the emerging trends in the
IT marketplace. ]]></Text_for_Paragraph_1>
</Script>=20
</page>=20
</module


Report this thread to moderator Post Follow-up to this message
Old Post
John Gauger
05-24-05 08:55 AM


Re: read and edit xml with PHP
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=3D"1.0" standalone=3D"yes"?>
> <module name=3D"GS02" course=3D"Demo">
>         <page>
>                 <Name><![CDATA[ c0300010 (Ref Num 772) ]]></Name>
>
> <Screen_Type><![CDATA[Text_wit=ADh_Image]]></Screen_Type>
>                 <Description><![CDATA[   ]]></Description>
>                 <Script>
>                         <Text_for_Paragraph_1><![CDATA=AD[ Welcome to
> lesson 1 of module 2.
>   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=2ES. 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.

--=20
Oli


Report this thread to moderator Post Follow-up to this message
Old Post
Oli Filth
05-24-05 08:55 AM


Re: read and edit xml with PHP
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/


Report this thread to moderator Post Follow-up to this message
Old Post
teemu.valimaki@gmail.com
05-24-05 01:56 PM


Re: read and edit xml with PHP
http://minixml.psychogenic.com/

seems to be even better.


Report this thread to moderator Post Follow-up to this message
Old Post
Teemu Välimäki
05-26-05 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:32 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.