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

Fitse,

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).

Be sure:
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.

Good luck

Airshow

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.

Airshow

What I want is to edit(delete and insert) values in the xml using php not a text editor thank you anyway.

Fitse ,

Aha, I feared as much!

I can offer two approaches:

  1. 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.
  2. 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.

Advantages/disadvantages?
(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.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.