An attribute named id means nothing special to a parser; only a DTD or schema can make it an ID. The xml:id Recommendation (September 2005) fixed that: xml:id is an ID in every document, no schema needed. Its value must be a name without a colon (an NCName: b3, not 3) and unique in the document, which makes it the target for XPath's id() and for fragment identifiers such as catalog.xml#b3 (XPointer Fragment Identifiers):
xquery -s:booknest-tour.xml -qs:'id("b3")/title[1]/string()'
printf '<c><b xml:id="b3"/><b xml:id="b3"/><b xml:id="3"/></c>\n' > ids.xml
xmllint --noout ids.xml 2>&1 | grep error"Salt and Saffron" ids.xml:1: element b: validity error : ID b3 already defined ids.xml:1: parser error : xml:id : attribute value 3 is not an NCName
id() uses the parser's ID index instead of scanning the tree. BookNest's main catalog keeps a plain id, as most data vocabularies do, so there id("b3") finds nothing until a DTD or XSD declares it (Document Type Definitions and XSD 1.1 Types); //book[@id = "b3"] always works. IDs are unique only within one document, so prefix them when you merge feeds.
xml id
This special attribute is used to assign a single, unique name to an element. This helps XML processors make sub-resource linking robust.<?xml version="1.0" encoding="UTF-8"?>
<gb:book xmlns:gb="http://GoldenBookstore.com" xml:id="b123321">
<title>Harry Potter</title>
</gb:book>