EDOBE XDOM TAKE 6 IR - PRODUCTSHEET Spezifikationen Seite 240

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 304
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 239
CHAPTER 9: Integrating XML into JavaScript The XML Object 240
Modifying XML elements and attributes
You can change an element by assigning a value to the corresponding property.
X If the value assigned is an XML element, the element is simply replaced. If there are multiple elements
of the same type, the first element is replaced, and all other elements are deleted.
X If the value assigned is not XML, it is converted to a string, and the content of the element is replaced
with that string.
X If no element of this type is present, a new element is appended to the XML.
You can change the values of attributes using the same technique.
Modification examples
X In the sample XML, the third book has several <author> elements. This statement replaces all of them
with a single element, containing a new string:
bookstoreXML.book[2].author = "Charles ’Lewis Carroll’ Dodgeson";
The result is this XML:
<book category="CHILDREN">
<title lang="en">Alice’s Adventures in Wonderland</title>
<author>Charles ’Lewis Carroll’ Dodgeson</author>
<year>1865</year>
<price>29.99</price>
</book>
X
To replace just the first author, leaving all the other authors in place, use this statement:
bookstoreXML.book[2].author[0] = "Charles Dodgeson, aka Lewis Carroll";
X
This statement changes the content of the <year> element in the second book. ExtendScript
automatically converts the numeric value to a string:
bookstoreXML.book[1].year = 1901;
X
This following statement adds a new <rating> element to the second book:
bookstoreXML.book[1].rating = "*****";
The result is this XML:
<book category="CHILDREN">
<title lang="en">The Wonderful Wizard of Oz</title>
<author>L. Frank Baum</author>
<year>1900</year>
<price>39.95</price>
<rating>*****</rating>
</book>
X
This statement changes the value of the category attribute of the second book:
bookstoreXML.book[1].@category = "LITERATURE, FANTASY"
Seitenansicht 239
1 2 ... 235 236 237 238 239 240 241 242 243 244 245 ... 303 304

Kommentare zu diesen Handbüchern

Keine Kommentare