in reply to Re^6: language selection via libxml
in thread language selection via libxml

OK, numbers do not have to be enclosed in quotes, and a valid identifier cannot start with a digit. Try using "a" and "b" as the identifiers, though.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^8: language selection via libxml
by tangent (Parson) on Jan 20, 2014 at 14:05 UTC
    I see. So when I changed the ID values to 'a' and 'b' the only one that worked was the one with single quotes:
    "/language/$language/widget[\@ID='$id']"
    I'm not quite sure what you mean by "a valid identifier cannot start with a digit" - what does 'identifier' refer to?
      The reason why 1 cannot be mistaken for an element name is that element names cannot start with digits. Use "a" and "b" with the following XML to see what is matched against what:
      #!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $tree = 'XML::LibXML'->load_xml(string => <<'EOT'); <?xml version="1.0"?> <language> <english> <widget ID="a">input</widget> <widget ID="b">output</widget> </english> <deutsch> <widget ID="b"> eingabe <b>b</b> </widget> <widget ID="b">ausgabe</widget> </deutsch> </language> EOT test('english', 'a'); test('deutsch', 'b'); sub test { my ($language,$id) = @_; my @result = $tree->findnodes("/language/$language/widget[\@ID=$id +]"); print $_->textContent . "\n" for @result; my @result2 = $tree->findnodes("/language/$language/widget[\@ID='$ +id']"); print $_->textContent . "\n" for @result2; }
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Thanks choroba, I think I've "got it" now. I have updated my original reply.