2 Copyright (c) 2008, Adobe Systems Incorporated
\r
5 Redistribution and use in source and binary forms, with or without
\r
6 modification, are permitted provided that the following conditions are
\r
9 * Redistributions of source code must retain the above copyright notice,
\r
10 this list of conditions and the following disclaimer.
\r
12 * Redistributions in binary form must reproduce the above copyright
\r
13 notice, this list of conditions and the following disclaimer in the
\r
14 documentation and/or other materials provided with the distribution.
\r
16 * Neither the name of Adobe Systems Incorporated nor the names of its
\r
17 contributors may be used to endorse or promote products derived from
\r
18 this software without specific prior written permission.
\r
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
\r
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
\r
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
\r
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
\r
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
\r
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
\r
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
33 package com.adobe.utils
\r
36 public class XMLUtil
\r
39 * Constant representing a text node type returned from XML.nodeKind.
\r
41 * @see XML.nodeKind()
\r
43 * @langversion ActionScript 3.0
\r
44 * @playerversion Flash 9.0
\r
46 public static const TEXT:String = "text";
\r
49 * Constant representing a comment node type returned from XML.nodeKind.
\r
51 * @see XML.nodeKind()
\r
53 * @langversion ActionScript 3.0
\r
54 * @playerversion Flash 9.0
\r
56 public static const COMMENT:String = "comment";
\r
59 * Constant representing a processing instruction type returned from XML.nodeKind.
\r
61 * @see XML.nodeKind()
\r
63 * @langversion ActionScript 3.0
\r
64 * @playerversion Flash 9.0
\r
66 public static const PROCESSING_INSTRUCTION:String = "processing-instruction";
\r
69 * Constant representing an attribute type returned from XML.nodeKind.
\r
71 * @see XML.nodeKind()
\r
73 * @langversion ActionScript 3.0
\r
74 * @playerversion Flash 9.0
\r
76 public static const ATTRIBUTE:String = "attribute";
\r
79 * Constant representing a element type returned from XML.nodeKind.
\r
81 * @see XML.nodeKind()
\r
83 * @langversion ActionScript 3.0
\r
84 * @playerversion Flash 9.0
\r
86 public static const ELEMENT:String = "element";
\r
89 * Checks whether the specified string is valid and well formed XML.
\r
91 * @param data The string that is being checked to see if it is valid XML.
\r
93 * @return A Boolean value indicating whether the specified string is
\r
96 * @langversion ActionScript 3.0
\r
97 * @playerversion Flash 9.0
\r
99 public static function isValidXML(data:String):Boolean
\r
105 xml = new XML(data);
\r
112 if(xml.nodeKind() != XMLUtil.ELEMENT)
\r
121 * Returns the next sibling of the specified node relative to the node's parent.
\r
123 * @param x The node whose next sibling will be returned.
\r
125 * @return The next sibling of the node. null if the node does not have
\r
126 * a sibling after it, or if the node has no parent.
\r
128 * @langversion ActionScript 3.0
\r
129 * @playerversion Flash 9.0
\r
131 public static function getNextSibling(x:XML):XML
\r
133 return XMLUtil.getSiblingByIndex(x, 1);
\r
137 * Returns the sibling before the specified node relative to the node's parent.
\r
139 * @param x The node whose sibling before it will be returned.
\r
141 * @return The sibling before the node. null if the node does not have
\r
142 * a sibling before it, or if the node has no parent.
\r
144 * @langversion ActionScript 3.0
\r
145 * @playerversion Flash 9.0
\r
147 public static function getPreviousSibling(x:XML):XML
\r
149 return XMLUtil.getSiblingByIndex(x, -1);
\r
152 protected static function getSiblingByIndex(x:XML, count:int):XML
\r
158 out = x.parent().children()[x.childIndex() + count];
\r