EDOBE XDOM TAKE 6 IR - PRODUCTSHEET Especificaciones Pagina 239

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 304
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 238
CHAPTER 9: Integrating XML into JavaScript The XML Object 239
Accessing XML attributes
Attribute are properties of their parent elements. In ExtendScript, access an attribute name by using a
preceding at-sign (
@). An attribute property is a one-element list, which contains an XML object for the
value of the attribute. For example:
bookstoreXML.book [0].@category;
This returns the category attribute of the first book, whose value is the string “COOKING”.
To access all
category attributes of all books, use this statement:
bookstoreXML.book.@category
You can reference a set of elements with a particular attribute value, using a predicate in this form:
element.(@attribute == value)
For example, this statement returns only book elements that have a category attribute with the value
"CHILDREN":
bookstoreXML.book.(@category == "CHILDREN");
Viewing XML objects
The XML object, like all ExtendScript objects, has a toString() method that serializes the contents into a
string. In this case, the string contains only the text content of the element, not the tags. For example, for
the element
<x>text</x>, the toString() method returns “text.
This method is called when you evaluate the object in the JavaScript Console of the ExtendScript Toolkit. It
recreates the XML text that the object encapsulates. Thus, if you evaluate the object
bookstoreXML.book[1] in the Console, you see the XML text for the encapsulated tree, formatted with
line feeds and spaces:
> bookstoreXML.book[1];
<book category="CHILDREN">
<title lang="en">The Wonderful Wizard of Oz</title>
<author>L. Frank Baum</author>
<year>1900</year>
<price>39.95</price>
</book>
If you evaluate an object with a text value, you see the text value. For example:
> bookstoreXML.book[1].@category;
CHILDREN
If you access multiple values, the values are concatenated:
> bookstoreXML.book.@category
COOKINGCHILDRENCHILDRENMUSIC
The toXMLString() method serializes the entire element, including the tags, into a string. For example, for
the element
<x>text</x>, the method returns “<x>text</x>”.
Vista de pagina 238
1 2 ... 234 235 236 237 238 239 240 241 242 243 244 ... 303 304

Comentarios a estos manuales

Sin comentarios