Write back to an XML file
I was wondering if this is possible, I'm not looking for code, i just want to be pointed in the right direction - php, asp or javascript. I have an xml file:
<?xml version="1.0" encoding="utf-8"?>
<Groups>
<Group>
<groupNum&g开发者_如何学JAVAt;</groupNum>
<purgeGroup></purgeGroup>
<DupeRecs>
<DupeRec>
<Name></Name>
<Duplicate></Duplicate>
</DupeRec>
<DupeRec>
<Name></Name>
<Duplicate></Duplicate>
</DupeRec>
</DupeRecs>
</Group>
</Groups>
I would like to be able to load this into a web page and have the Duplicate tag display as a checkbox the user can the check/uncheck whether the record is a duplicate and this is written back to the xml file
Broadly, Here are the steps I would suggest :
- "Deserialize" the XML into a corresponding object
- Display the editable fields in a HTML form on your Web Page
- Process the HTML Form action and update your "Deserialized" object.
- "Serialize" the result back into the XML file.
You have to take care of multiple edits on the file using some locking mechanism.
I think the best way would be to while parsing the XML file for display, save it into certain variables that can be easily edited, and set these to the new variables for your XML file. When you have everything how you want it in the variables, re-assemble it and use the fopen(), fwrite() and fclose() commands to re-write the whole file.
EDIT: You could also look into PHP's XMLWriter functions.
I'm not sure what you mean by "load this into a webpage" but to have the Duplicate tag display as a checkbox suggests you want to convert the XML to a UI, for this I'd recommend XSLT which can be used to convert XML to anything including ASPX, PHP or JavaScript.
As for writing this back to the XML again I don't know where the XML file is but it is likely you want to send the user response back to the server somehow and that could be done in many ways.
In conclusion if your XML content is on the server then use XSLT to create a web page to display the UI and send the data back to the server.
If your XML content is client side then try Silverlight.
精彩评论