Hello everyone, I have an xml document that contains the captions of photos in a photo gallery I wanted to put the caption after uploadind the photos and also delete a specific caption Like <caption>Name1</caption>
<caption>Name2</caption> can anyone tell me how to edit the xml
XML is text, just like HTML.
You can therefore edit in something as simple as MS Notepad, though XML-savvy products are available - eg. from Altova (IIRC).
a) Not to violate the XLM schema to which your XML file conforms (if specified). ie. You can't just do what you want in XML.
b) To maintain the XML's "well-formedness" (eg. tags must balance and must be properly nested).
Failure to observe rules will yield unusable XML so make sure you back up the file before you start.
I think I'm right to say that the more sophisticated XML editors (I already mention one above) will check your work as you type, to a greater or lesser extent.
I have edited and created XML files from scratch using FirstPage 2000, which is not XML-savvy. But by saving the file regularly, I was able to use IE to browse the file and thus check for well-formedness and to view the XML in a decent, collapsible format as I edited.
And I forgot to say, I think this topic should be moved from PHP to the XML, XSLT and XPATH forum.
As I have interpreted the question, php is not involved, just manual edit. Of course I may be wrong.
What I want is to edit(delete and insert) values in the xml using php not a text editor thank you anyway.
Aha, I feared as much!
I can offer two approaches:
- Write a php script to read the source XML file line-by-line (hopefully tag-by-tag), string-handle as necessary to edit the lines of interest and write to sink file as you go.
- Write a php script to read the source XML file into php, parse it into nested arrays, then loop through the nested array to modify content as necessary, then convert back to XML and reite to sink file.
(1) is simpler but (2) is better supported by available library objects to do the read/write parsing.
I have limited experience in XML-PHP conversion so am unfortunately unable to make specific recommendations. I wrote an RSS reader in php from scratch a few years ago and wish I had based it on a decent 3rd party XML class - it would have saved me a lot of time. However, you may be able to avoid a lot of the complexity by adopting my approach (1).
Not sure I have helped a lot so good luck.