[xml] How to select a node based on attribute values?

Fist off, I'm a total newbie when it comes to libxml. I've been able to work my way through some examples, and produce working code, but I'm not entirely happy with the result, and I would like some advice.

I have an XML tree that looks like this:

   <plc id="1">
      <some stuff/>
   <plc id="2">
      <some other stuff/>

I have a relatively small number (< 50) of the plc nodes, but the whole tree is pretty big.

What is the best (or simplest way) to retrieve the information for plc 2?

Should I pull all of the plc elements using xmlXPathEvalExpression, and then iterate over them with xmlGetProp looking for an id attribute with a value of "2"?

Or is there some other way to directly specify, I want this element with these attributes?

Thanks for any guidance.... The docs are really thorough, but libxml is so rich that the learning curve is a killer.....


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]