PhpxPath for parsing xml files

Source: Internet
Author: User
PhpxPath: long term for parsing xml files-for better description, the content of an xml file is roughly as follows: & lt; root & gt; & nbsp; & lt; collectionid = & quot; co1 & quot; & gt; & nbsp; & lt; categoryi php xPath parsing xml files
Long story-better description
In the past, there was an xml file with the following content:


Aaa
Bbb


Ccc
Ddd


It is clear that there can be several collections, and each collection contains several category. and the collection and category IDs are unique. I used to modify the node value of category. xpath is always used. for example, if you change the value of category whose id is ca1, you can
$ Xpath-> query ("/root/collection/category [@ id = '" ca1 "']"); locate and modify it.

However, pay attention to it! Turning point!
But now the xml file format has changed:




Aaa



Bbb


You can change it to a category based on the previous one, and there can be N category. Therefore, if you change the value of a specific category, I won't. For example, I don't know how to change the category value of id ca4 to xxx.
I still want to use xpath, but I don't know how to use it.
$ Xpath-> query ("/root/collection/here I don't know how to write/category [@ id = '" aaa "']");

As I know before, there must be a category under the collection and there is only one layer, so I can easily locate it. Now I won't. Please help me. Thank you.

------ Solution --------------------
/Root/collection // category [@ id = 'AAA']

In this way.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.