--- /dev/null
+/*\r
+ Copyright (c) 2008, Adobe Systems Incorporated\r
+ All rights reserved.\r
+\r
+ Redistribution and use in source and binary forms, with or without \r
+ modification, are permitted provided that the following conditions are\r
+ met:\r
+\r
+ * Redistributions of source code must retain the above copyright notice, \r
+ this list of conditions and the following disclaimer.\r
+ \r
+ * Redistributions in binary form must reproduce the above copyright\r
+ notice, this list of conditions and the following disclaimer in the \r
+ documentation and/or other materials provided with the distribution.\r
+ \r
+ * Neither the name of Adobe Systems Incorporated nor the names of its \r
+ contributors may be used to endorse or promote products derived from \r
+ this software without specific prior written permission.\r
+\r
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR \r
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+*/\r
+\r
+package com.adobe.utils\r
+{\r
+\r
+ public class XMLUtil\r
+ {\r
+ /**\r
+ * Constant representing a text node type returned from XML.nodeKind.\r
+ * \r
+ * @see XML.nodeKind()\r
+ * \r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ */\r
+ public static const TEXT:String = "text";\r
+ \r
+ /**\r
+ * Constant representing a comment node type returned from XML.nodeKind.\r
+ * \r
+ * @see XML.nodeKind()\r
+ * \r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ */ \r
+ public static const COMMENT:String = "comment";\r
+ \r
+ /**\r
+ * Constant representing a processing instruction type returned from XML.nodeKind.\r
+ * \r
+ * @see XML.nodeKind()\r
+ * \r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ */ \r
+ public static const PROCESSING_INSTRUCTION:String = "processing-instruction";\r
+ \r
+ /**\r
+ * Constant representing an attribute type returned from XML.nodeKind.\r
+ * \r
+ * @see XML.nodeKind()\r
+ * \r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ */ \r
+ public static const ATTRIBUTE:String = "attribute";\r
+ \r
+ /**\r
+ * Constant representing a element type returned from XML.nodeKind.\r
+ * \r
+ * @see XML.nodeKind()\r
+ * \r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ */ \r
+ public static const ELEMENT:String = "element";\r
+ \r
+ /**\r
+ * Checks whether the specified string is valid and well formed XML.\r
+ * \r
+ * @param data The string that is being checked to see if it is valid XML.\r
+ * \r
+ * @return A Boolean value indicating whether the specified string is\r
+ * valid XML.\r
+ * \r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ */\r
+ public static function isValidXML(data:String):Boolean\r
+ {\r
+ var xml:XML;\r
+ \r
+ try\r
+ {\r
+ xml = new XML(data);\r
+ }\r
+ catch(e:Error)\r
+ {\r
+ return false;\r
+ }\r
+ \r
+ if(xml.nodeKind() != XMLUtil.ELEMENT)\r
+ {\r
+ return false;\r
+ }\r
+ \r
+ return true;\r
+ }\r
+ \r
+ /**\r
+ * Returns the next sibling of the specified node relative to the node's parent.\r
+ * \r
+ * @param x The node whose next sibling will be returned.\r
+ * \r
+ * @return The next sibling of the node. null if the node does not have \r
+ * a sibling after it, or if the node has no parent.\r
+ * \r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ */ \r
+ public static function getNextSibling(x:XML):XML\r
+ { \r
+ return XMLUtil.getSiblingByIndex(x, 1);\r
+ }\r
+ \r
+ /**\r
+ * Returns the sibling before the specified node relative to the node's parent.\r
+ * \r
+ * @param x The node whose sibling before it will be returned.\r
+ * \r
+ * @return The sibling before the node. null if the node does not have \r
+ * a sibling before it, or if the node has no parent.\r
+ * \r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ */ \r
+ public static function getPreviousSibling(x:XML):XML\r
+ { \r
+ return XMLUtil.getSiblingByIndex(x, -1);\r
+ } \r
+ \r
+ protected static function getSiblingByIndex(x:XML, count:int):XML \r
+ {\r
+ var out:XML;\r
+ \r
+ try\r
+ {\r
+ out = x.parent().children()[x.childIndex() + count]; \r
+ } \r
+ catch(e:Error)\r
+ {\r
+ return null;\r
+ }\r
+ \r
+ return out; \r
+ }\r
+ }\r
+}
\ No newline at end of file