Finding an Element with a Particular ID

To obtain the element that has a particular identifier (ID), the DTD must specify an attribute for that element. The type of this attribute must be ID. The name of the attribute is not significant, though it is typically id. If there is such an attribute, you can call the id() function to obtain the element with a particular ID. The format is

node-set  id(object) 
               

            

The id() function evaluates to a set. It ignores the context node set except to evaluate the function's argument. The result set contains an element node that has an attribute of type ID whose value is identical to the string the object argument evaluates to. The element node can appear anywhere in the document that is being queried.

For example:

id("special")
               

            

This query searches for an element that has an attribute whose

  • Type is ID
  • Value is special

Details about working with IDs are in the following topics:

The id() Function's Argument

When the id() function's argument is of type node-set, the result is the union of the results of applying id() to the string value of each of the nodes in the argument node set.

When the argument of id() is any other type, the XPath processor converts the argument to a string as if by a call to the string() function. The XPath processor splits the string into a white-space-separated list of tokens. The result is a node set that contains the elements in the same document as the context node that have a unique ID equal to any of the tokens in the list.

Unique IDs

An element node can have a unique ID. This is the value of the attribute that is declared in the DTD as type ID. No two elements in a document can have the same unique ID. If an XML processor reports two elements in a document as having the same unique ID (which is possible only if the document is invalid), the second element is treated as not having a unique ID.

If a document does not have a DTD, the id() function always returns an empty node list.

Database-to-XML Mapping

Stylus Studio features several database-to-XML mapping tools that allow you to easily query a relational database using SQL/XML or SQL and render the results as XML. Stylus Studio also supports the world's first and only visual SQL/XML Editor!

Getting EDI to XML and back to EDI Again: Round Trip Engineering using Stylus Studio URL Adapters

A free online video demonstration shows how to use Stylus Studio's Adapter URL technologies to convert EDI to XML and back again. Convert, validate, view and edit EDIFACT data directly in Stylus Studio.

Generate XSD

Stylus Studio® can generate an industry standard W3C XSD (or DTD) by correctly inferring an XML data model from an XML instance document.

XML Schema Documentation Generator

Stylus Studio's XML Schema Editor includes an integrated XML Schema documentation generator, allowing you to easily publish XML content models defined in XML Schema in a convenient, HTML format. A screenshon of the XML Schema Editor is shown here.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member