Flash CS3 文档 |
|||
| ActionScript 3.0 编程 > 处理 XML > XML 对象 | |||
XML 对象可能表示 XML 元素、属性、注释、处理指令或文本元素。
XML 对象分为包含“简单内容”和包含“复杂内容”两类。有子节点的 XML 对象归入包含复杂内容的一类。如果 XML 对象是属性、注释、处理指令或文本节点之中的任何一个,我们就说它包含简单内容。
例如,下面的 XML 对象包含复杂内容,包括一条注释和一条处理指令:
XML.ignoreComments = false;
XML.ignoreProcessingInstructions = false;
var x1:XML =
<order>
<!--这是一条注释。 -->
<?PROC_INSTR sample ?>
<item id='1'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<item id='2'>
<menuName>fries</menuName>
<price>1.45</price>
</item>
</order>
如下面的示例所示,现在可以使用 comments() 和 processingInstructions() 方法创建新的 XML 对象,即注释和处理指令:
var x2:XML = x1.comments()[0]; var x3:XML = x1.processingInstructions()[0];
XML 类有五个静态属性:
ignoreComments 和 ignoreProcessingInstructions 属性确定分析 XML 对象时是否忽略注释或处理指令。 ignoreWhitespace 属性确定在只由空白字符分隔的元素标签和内嵌表达式中是否忽略空白字符。 prettyIndent 和 prettyPrinting 属性用于设置由 XML 类的 toString() 和 toXMLString() 方法返回的文本的格式。有关这些属性的详细信息,请参阅《ActionScript 3.0 语言和组件参考》。
以下方法用于处理 XML 对象的分层结构:
appendChild() child() childIndex() children() descendants() elements() insertChildAfter() insertChildBefore() parent() prependChild() 以下方法用于处理 XML 对象属性 (attribute):
attribute() attributes() 以下方法用于处理 XML 对象属性 (property):
hasOwnProperty() propertyIsEnumerable() replace() setChildren() 以下方法用于处理限定名和命名空间:
addNamespace() inScopeNamespaces() localName() name() namespace() namespaceDeclarations() removeNamespace() setLocalName() setName() setNamespace() 以下方法用于处理和确定某些类型的 XML 内容:
comments() hasComplexContent() hasSimpleContent() nodeKind() processingInstructions() text() 以下方法用于转换为字符串和设置 XML 对象的格式:
defaultSettings() setSettings() settings() normalize() toString() toXMLString() 还有其它几个方法:
contains() copy() valueOf() length() 有关这些方法的详细信息,请参阅《ActionScript 3.0 语言和组件参考》。
Flash CS3
当前页: http://livedocs.adobe.com/flash/9.0_cn/main/00000125.html