homepage Welcome to WebmasterWorld Guest from 54.204.73.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP's xpat
inserting data in an xml file
copongcopong

10+ Year Member



 
Msg#: 1083 posted 4:43 am on Oct 7, 2002 (gmt 0)

Anyone here seen a script or have tried to create script to insert a data into an xml file using xpat in php?

Theoretically i know it is possible with domxl however i read that it uses a lot of server's resources and i beleive that xpat is faster.

i could imagine that it is feasible, probable, imaginable, workable, etc ... with some php coding with expat? is it or its just a pigment of my imagination? :)

<quotes>I am enough of an artist to draw freely upon my imagination. Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world.
--Albert Einstein
</quotes>

 

lorax

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 1083 posted 1:44 pm on Oct 7, 2002 (gmt 0)

copongcopong,

Have you looked here?

[phpbuilder.com...]

copongcopong

10+ Year Member



 
Msg#: 1083 posted 10:50 pm on Oct 7, 2002 (gmt 0)

thanks lorax but it did not mentioned anything about inserting a data into an xml file. ... sort of appending/pre-pending the data in the xml file. Anyway, I also have a working example of using php's xpat in my site and i am doing some experiments right now.

but doing a mental experiment, i could see it worked. :)

lorax

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 1083 posted 1:32 pm on Oct 8, 2002 (gmt 0)

Sorry about that copongcopong, I should have read it myself first. Interesting idea, there has to be someone here that has the answer. I'd like to know too!

copongcopong

10+ Year Member



 
Msg#: 1083 posted 10:07 pm on Oct 8, 2002 (gmt 0)

Here is what i really like to accomplish. it would be sort of a cms but a very crude one. It is a flat (xml) file based, no database.

1. Create a form that would accept data. (ok)

2. Data from the form would then be inserted into an xml file. (thinking)

3. Display the xml file. (ok)

The problem that needs to be address is when inserting a data into an xml file. Here is an example.

<?xml head?>
<mother>
<child>data</child>
</mother>

then from the form, it would then insert another <child>data2</child>

to make the xml file,

<?xml head?>
<mother>
<child>data2</child>
<child>data</child>
</mother>
--------------------------
on step 2, one idea i am thinking is to read the xml file, string replace the <?xmlhead?> and <mother> with <?xmlhead?>+<mother>+<child>data2</child> then save the xml file.

another idea i have is to use xpat to read the xml file, when it reads <mother>, it would insert the data from the form then let xpat continue reading the file, then save (or overwrite) the xml file.

am i crazy?

copongcopong

10+ Year Member



 
Msg#: 1083 posted 11:50 pm on Oct 8, 2002 (gmt 0)

anyway I find this site: [outer-court.com...] uses an php and xml file to run a forum, ... its kinda interesting but i do prefer to create a simple one for my learning process.

lorax

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 1083 posted 1:51 am on Oct 9, 2002 (gmt 0)

copongcopong,
In thinking more about this I wonder if we're making this more difficult than it needs to be. Why, for instance, couldn't you just write the form variables out using fwrite()? Build the structure of the XML doc within PHP using variables and strings and then write it all out to the drive. Am I missing something obvious?

copongcopong

10+ Year Member



 
Msg#: 1083 posted 2:46 am on Oct 9, 2002 (gmt 0)

Yes that is another good idea. Could you be more specific?

Anyway, my main problem really is adding the data into the xml file and after adding the data there, it should preserve its structure.

lorax

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 1083 posted 1:34 pm on Oct 9, 2002 (gmt 0)

Well, what I'm thinking is this:

Form fields "mother", "child"

When the handler gets the form results we know Mother is the container for the children so we could write

$mom = "<mother><child>".$child."</child></mother>";

Right? Mind you I'm not that fluent with XML syntax yet.

And then write out the vars to an XML file using fwrite()

[php.net...]

There are two other options I thought of. Use an XML database [xml.com...]

or if you're using a MySQL database, go ahead and insert the form data into the database and then perform a mysqldump -X to create a well formed XML document

[mysql.com...]

Gregg

copongcopong

10+ Year Member



 
Msg#: 1083 posted 12:03 am on Nov 1, 2002 (gmt 0)

Here is a site that I have check out that uses expat to insert data to xml file:

[o-idev.com...]

i believe it is from a book oublished by wrox.

however, i have created my script and it is very simple and it works to insert data on the first part or on top of the xml data. it uses the stringreplace in php.

here is an example of the xml file:
<?xml version="1.0"?>
<mother>
<child>data0</child>
</mother>

the string from the form would be: <?xml version="1.0"?> <mother><child>data1</child>

then stringreplace the "<?xml version="1.0"?><mother>" on the actual xml file with the one that came from the the form. then save it.

therefore making the xml file:
<?xml version="1.0"?>
<mother>
<child>data1</child>
<child>data0</child>
</mother>

sort of appending it on top or should i say pre-ppend.

then would be parse by expat.

peace. =)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved