Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changes between Version 6 and Version 7 of TutXmlPath

Show
Ignore:
Author:
kris (IP: 17.228.23.90)
Timestamp:
03/28/09 04:08:04 (15 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TutXmlPath

    v6 v7  
    106106import tango.io.device.File; 
    107107import tango.io.Stdout; 
    108 import tango.text.Util; 
     108import Util = tango.text.Util; 
    109109import tango.text.xml.Document; 
    110110 
    117117    doc.parse(xml); 
    118118 
     119    // a custom filter 
     120    bool test(doc.Node node) 
     121    { 
     122        auto attr = node.attributes.name(null, "id"); 
     123        return attr && Util.contains(attr.value, 'B'); 
     124    } 
     125 
    119126    // get the root element 
    120127    auto root = doc.elements; 
    121128 
    122129    // query the doc for all country elements with an id attribute that contains a 'B' 
    123     auto result = root.query.descendant("country").filter((doc.Node node) { 
    124         return contains!(char)(node.attributes.name(null, "id").value, 'B'); 
    125     }); 
     130    auto result = root.query.descendant("country").filter(&test); 
    126131 
    127132    foreach (e; result) {