Updating XML file in PHP
Moderator: General Moderators
-
dagadakrishna
- Forum Commoner
- Posts: 29
- Joined: Fri Jan 19, 2007 3:30 am
Updating XML file in PHP
hi
this is krishna kanth dagada
today only i joned in this forum .
my doubt is :Using PHP can i update XML data according to uer choice,is it posiible r not
details: a page consists of form with some fields where the value or data of the fields comes from XML file.
If user enters some values in the fields ans clicks update button then XML file has to update in server .
is it posiible by using PHP
waiting for reply
this is krishna kanth dagada
today only i joned in this forum .
my doubt is :Using PHP can i update XML data according to uer choice,is it posiible r not
details: a page consists of form with some fields where the value or data of the fields comes from XML file.
If user enters some values in the fields ans clicks update button then XML file has to update in server .
is it posiible by using PHP
waiting for reply
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
-
dagadakrishna
- Forum Commoner
- Posts: 29
- Joined: Fri Jan 19, 2007 3:30 am
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
eagerly eh? how exciting 
There's SimpleXml or DOM for processing XML. file_get_contents(), file_put_contents() could be useful. And if you google you'll find a whole bunch of tutorials on getting data from forms.
Please note: We help people with their code, we don't write it for them. I'll be of more use to you if you come back with some code I can comment on.
There's SimpleXml or DOM for processing XML. file_get_contents(), file_put_contents() could be useful. And if you google you'll find a whole bunch of tutorials on getting data from forms.
Please note: We help people with their code, we don't write it for them. I'll be of more use to you if you come back with some code I can comment on.
-
dagadakrishna
- Forum Commoner
- Posts: 29
- Joined: Fri Jan 19, 2007 3:30 am
Updating XML file in PHP
feyd | Please use
AND THIS IS MY HTML FILE
so if users enters some values in fields like cameras and rangers and clicks update button then it has to update the attributes of Number_of_Cameras,Number_of_Rangers in the xml file .
this is my problem hopeu understood my question
c u bye waiting for reply................
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi thanks for giving reply
but i thnk u did nt understood my question
this is my XML
[syntax="xml"]<?xml version="1.0" encoding="ISO-8859-1"?>
<Book Revision_Number="0">
<System_Configuration Name="Tunnel_1" Number_of_Cameras="4" Number_of_Rangers="1" Update_Count="0"/>
<Ranger_Configuration Name="Tunnel_1" Number_of_Cameras="4" Number_of_Rangers="1" Update_Count="0"/>
</Book>AND THIS IS MY HTML FILE
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<form action="something.php" method="post">
<CENTER><INPUT TYPE="text" NAME="camera">Cameras
<INPUT TYPE="text" NAME="ranger">Rangers<BR><BR>
<INPUT TYPE="submit" value=update>
</CENTER>
</form>
</BODY>
</HTML>so if users enters some values in fields like cameras and rangers and clicks update button then it has to update the attributes of Number_of_Cameras,Number_of_Rangers in the xml file .
this is my problem hopeu understood my question
c u bye waiting for reply................
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
What didn't I understand? Those technologies are perfectly suited to what you are trying to do (possibly DOM is better than SimpleXML for this). As I remember PHP Power Programming has a chapter dedicated to XML.
Welcome. Be sure to use
Code: Select all
and/orCode: Select all
in your posts when adding code so it helps people with reading them. Thanks![/b]
[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]11.[/b] Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.[/quote]-
dagadakrishna
- Forum Commoner
- Posts: 29
- Joined: Fri Jan 19, 2007 3:30 am
updating XML file in server
feyd | Please use
EVERYTHING IS COMPLEATED but one small problem
this is my XML file
here is my PHP code[/syntax]
here iam trying to change the roll attribute value of angles node, according to the user entered value in roll field.
But my problem is there r so many angles nodes and roll attribute values in my xml file ,then how to update the desired roll attribute value can u suggest me ole.
another problem is if give window.location="user_updation.html"; where user_updation.html is the page where user updates so iam pointing to same page at last .if i give point to the same page by using this code whole page itself not working and if i remove this its working fine.so i did not kept any thing in script above.
ok bye ole
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi ole
what u told is correct ole i tried according to ur suggestion i succeded at last after one week,
THANK YOU VERY MUCH OLE.
EVERYTHING IS COMPLEATED but one small problem
this is my XML file
[syntax="xml"]<Mounting_Position Value="TOP">
<Angles Roll="10" Pitch="0" Yaw="0"/> <!-- RANGE: -110 to 110 UNITS: degrees -->
<Offsets X="00" Y="10" Z="0"/> <!-- RANGE: -50 to 50 inches UNITS: inches or cm -->
<!-- NOTE: The following are embedded in the Offset, but these needs better definition -->
<!-- Maximum_Range Value="10"/> -->
<!-- Distance_to_Scanline Value="00"/> -->
</Mounting_Position>EVERYTHING IS COMPLEATED but one small problem
this is my XML file
Code: Select all
<System_Configuration>
<Mounting_Position_a Value="TOP">
<Angles Roll="10" Pitch="0" Yaw="0"/> <!-- RANGE: -110 to 110 UNITS: degrees -->
<Offsets X="00" Y="10" Z="0"/> <!-- RANGE: -50 to 50 inches UNITS: inches or cm -->
<!-- NOTE: The following are embedded in the Offset, but these needs better definition -->
<!-- Maximum_Range Value="10"/> -->
<!-- Distance_to_Scanline Value="00"/> -->
</Mounting_Position_a>
<Mounting_Position_b Value="TOP">
<Angles Roll="10" Pitch="0" Yaw="0"/> <!-- RANGE: -110 to 110 UNITS: degrees -->
<Offsets X="00" Y="10" Z="0"/> <!-- RANGE: -50 to 50 inches UNITS: inches or cm -->
<!-- NOTE: The following are embedded in the Offset, but these needs better definition -->
<!-- Maximum_Range Value="10"/> -->
<!-- Distance_to_Scanline Value="00"/> -->
</Mounting_Position_b >
<Mounting_Position_c Value="TOP">
<Angles Roll="10" Pitch="0" Yaw="0"/> <!-- RANGE: -110 to 110 UNITS: degrees -->
<Offsets X="00" Y="10" Z="0"/> <!-- RANGE: -50 to 50 inches UNITS: inches or cm -->
<!-- NOTE: The following are embedded in the Offset, but these needs better definition -->
<!-- Maximum_Range Value="10"/> -->
<!-- Distance_to_Scanline Value="00"/> -->
</Mounting_Position_c>
</System_Configuration>here is my PHP code[/syntax]
Code: Select all
<html>
<head>
<title>Leapfrog</title>
</head>
<body>
<?php echo $_POST["T1"]; ?>
<?php
$doc = new DomDocument;
// We need to validate our document before refering to the id
$doc->validateOnParse = true;
//Load the save.xml file into DOMDocument
$doc->Load('../xml/leapfrog_configuration.xml');
// We retrieve the attribute named id of the employee element
$attr = $doc->getElementsByTagName('Angles')->item(2)->getAttribute('Roll');
$old=$attr;
$fname = "../xml/leapfrog_configuration.xml";
$fhandle = fopen($fname,"r");
$content = fread($fhandle,filesize($fname));
$content = str_replace($old, $_POST["T1"], $content);
echo $attr;
$fhandle = fopen($fname,"w");
fwrite($fhandle,$content);
fclose($fhandle);
echo "changed Succefully"
?>
<script>
</script>
</body>
<html>here iam trying to change the roll attribute value of angles node, according to the user entered value in roll field.
But my problem is there r so many angles nodes and roll attribute values in my xml file ,then how to update the desired roll attribute value can u suggest me ole.
another problem is if give window.location="user_updation.html"; where user_updation.html is the page where user updates so iam pointing to same page at last .if i give point to the same page by using this code whole page itself not working and if i remove this its working fine.so i did not kept any thing in script above.
ok bye ole
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by dagadakrishna on Tue Jan 23, 2007 5:33 am, edited 1 time in total.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
-
dagadakrishna
- Forum Commoner
- Posts: 29
- Joined: Fri Jan 19, 2007 3:30 am
hi ole
i made little bit changes in my code like changing item(0) to item(1) to get desired attribute its working fine but problem is if give window.location="user_updation.html"; where user_updation.html is the page where user updates so iam pointing to same page at last .if i give point to the same page by using this code whole page itself not working and if i remove this its working fine.so i did not kept any thing in script above.
bye ole
i made little bit changes in my code like changing item(0) to item(1) to get desired attribute its working fine but problem is if give window.location="user_updation.html"; where user_updation.html is the page where user updates so iam pointing to same page at last .if i give point to the same page by using this code whole page itself not working and if i remove this its working fine.so i did not kept any thing in script above.
bye ole
-
dagadakrishna
- Forum Commoner
- Posts: 29
- Joined: Fri Jan 19, 2007 3:30 am
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
dagadakrishna, since you've chosen to ignore your private messages, here's a public one:
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.