0

How do I use XPath in Vala on a Xml.Node object?

The only examples I can find is were a Context is created from a Doc object, but I don't have a Xml.Doc object to begin with. Is there a way I can convert Xml.Node into Xml.Doc? Or is there some other way?

The example I'm looking at is : https://live.gnome.org/Vala/XmlSample

Thanks.

Wayne
  • 914
  • 2
  • 13
  • 25

2 Answers2

1

The Xml.Node class has a Xml.Doc doc member. You should be able to use that to get the relevant Xml.Doc for a node.

nemequ
  • 16,623
  • 1
  • 43
  • 62
0

I will be interested on this too, here is what I have been doing so far (I am just learning Vala)

    // Get the node's name
    string node_name = iter->name;

    switch (node_name){
            case "host":
                    this.host = (string) iter->get_content ();
                break;   
            case "username":
                    this.username = (string) iter->get_content ();
                break;   
            case "password":
                    this.password = (string) iter->get_content ();
                break;   
            case "database":
                    this.database = (string) iter->get_content ();
                break;   
             case "port":
                    this.port = (int)iter->get_content ();
                break;   

 }

But for obvious reasons this works fine with a very small and simple xml but when you get to a more complex and bigger xml then your performance will suffer greatly.

kingletas
  • 44
  • 2
  • You can just use Xml.Node.doc to get the relevant Xml.Doc from the node which you can then use to evaluate an XPath query. – nemequ Aug 23 '12 at 06:12