1

I'm processing XML using Rhino 1.7R3 and have trouble accessing xml:id attribute.

var bond = new XML('<person xml:id="007" profession="agent">James Bond</person>');
print(bond); // "James Bond"
print(bond.@profession); // "agent"
print(bond.@xml:id); // ERROR: missing ) after argument list

I tried putting xml:id inside quotes and square brackets but it didn't solve the problem. Is there a way?


EDIT: I got it working by defining namespace. After that both of the methods Siva suggests work:

var xml = new Namespace("xml", "http://www.w3.org/XML/1998/namespace");
var bond = new XML('<person xml:id="007" profession="agent">James Bond</person>');
print(bond); // "James Bond"
print(bond.@profession); // "agent"
print(bond.@xml::id); // "007"
print(bond..@xml::id); // "007"
geca
  • 2,711
  • 2
  • 17
  • 26

1 Answers1

3

Try this way

print(bond.@xml::id);

or

print(bond..@xml::id);
Siva Charan
  • 17,940
  • 9
  • 60
  • 95
  • 1
    If you want to know what's happening here, it's that you're matching an `id` attribute in the predefined [`xml` namespace](http://www.w3.org/XML/1998/namespace), which is always http://www.w3.org/XML/1998/namespace and must always have prefix `xml`. You can declare other namespaces with `prefix = "uri"` or `var prefix = new Namespace('uri')` and then match with `prefix::` – Francis Avila Dec 03 '11 at 20:45
  • Siva & Francis, I got it working by combining your suggestions. Thanks. – geca Dec 04 '11 at 00:05