Mercurial > hg > audiodb
comparison bindings/as3/ext/com/adobe/utils/XMLUtil.as @ 732:3a0b9700b3d2
* Initial AS3 commit
author | mas01mj |
---|---|
date | Tue, 14 Sep 2010 16:47:10 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
731:65134dd772fc | 732:3a0b9700b3d2 |
---|---|
1 /* | |
2 Copyright (c) 2008, Adobe Systems Incorporated | |
3 All rights reserved. | |
4 | |
5 Redistribution and use in source and binary forms, with or without | |
6 modification, are permitted provided that the following conditions are | |
7 met: | |
8 | |
9 * Redistributions of source code must retain the above copyright notice, | |
10 this list of conditions and the following disclaimer. | |
11 | |
12 * Redistributions in binary form must reproduce the above copyright | |
13 notice, this list of conditions and the following disclaimer in the | |
14 documentation and/or other materials provided with the distribution. | |
15 | |
16 * Neither the name of Adobe Systems Incorporated nor the names of its | |
17 contributors may be used to endorse or promote products derived from | |
18 this software without specific prior written permission. | |
19 | |
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | |
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 */ | |
32 | |
33 package com.adobe.utils | |
34 { | |
35 | |
36 public class XMLUtil | |
37 { | |
38 /** | |
39 * Constant representing a text node type returned from XML.nodeKind. | |
40 * | |
41 * @see XML.nodeKind() | |
42 * | |
43 * @langversion ActionScript 3.0 | |
44 * @playerversion Flash 9.0 | |
45 */ | |
46 public static const TEXT:String = "text"; | |
47 | |
48 /** | |
49 * Constant representing a comment node type returned from XML.nodeKind. | |
50 * | |
51 * @see XML.nodeKind() | |
52 * | |
53 * @langversion ActionScript 3.0 | |
54 * @playerversion Flash 9.0 | |
55 */ | |
56 public static const COMMENT:String = "comment"; | |
57 | |
58 /** | |
59 * Constant representing a processing instruction type returned from XML.nodeKind. | |
60 * | |
61 * @see XML.nodeKind() | |
62 * | |
63 * @langversion ActionScript 3.0 | |
64 * @playerversion Flash 9.0 | |
65 */ | |
66 public static const PROCESSING_INSTRUCTION:String = "processing-instruction"; | |
67 | |
68 /** | |
69 * Constant representing an attribute type returned from XML.nodeKind. | |
70 * | |
71 * @see XML.nodeKind() | |
72 * | |
73 * @langversion ActionScript 3.0 | |
74 * @playerversion Flash 9.0 | |
75 */ | |
76 public static const ATTRIBUTE:String = "attribute"; | |
77 | |
78 /** | |
79 * Constant representing a element type returned from XML.nodeKind. | |
80 * | |
81 * @see XML.nodeKind() | |
82 * | |
83 * @langversion ActionScript 3.0 | |
84 * @playerversion Flash 9.0 | |
85 */ | |
86 public static const ELEMENT:String = "element"; | |
87 | |
88 /** | |
89 * Checks whether the specified string is valid and well formed XML. | |
90 * | |
91 * @param data The string that is being checked to see if it is valid XML. | |
92 * | |
93 * @return A Boolean value indicating whether the specified string is | |
94 * valid XML. | |
95 * | |
96 * @langversion ActionScript 3.0 | |
97 * @playerversion Flash 9.0 | |
98 */ | |
99 public static function isValidXML(data:String):Boolean | |
100 { | |
101 var xml:XML; | |
102 | |
103 try | |
104 { | |
105 xml = new XML(data); | |
106 } | |
107 catch(e:Error) | |
108 { | |
109 return false; | |
110 } | |
111 | |
112 if(xml.nodeKind() != XMLUtil.ELEMENT) | |
113 { | |
114 return false; | |
115 } | |
116 | |
117 return true; | |
118 } | |
119 | |
120 /** | |
121 * Returns the next sibling of the specified node relative to the node's parent. | |
122 * | |
123 * @param x The node whose next sibling will be returned. | |
124 * | |
125 * @return The next sibling of the node. null if the node does not have | |
126 * a sibling after it, or if the node has no parent. | |
127 * | |
128 * @langversion ActionScript 3.0 | |
129 * @playerversion Flash 9.0 | |
130 */ | |
131 public static function getNextSibling(x:XML):XML | |
132 { | |
133 return XMLUtil.getSiblingByIndex(x, 1); | |
134 } | |
135 | |
136 /** | |
137 * Returns the sibling before the specified node relative to the node's parent. | |
138 * | |
139 * @param x The node whose sibling before it will be returned. | |
140 * | |
141 * @return The sibling before the node. null if the node does not have | |
142 * a sibling before it, or if the node has no parent. | |
143 * | |
144 * @langversion ActionScript 3.0 | |
145 * @playerversion Flash 9.0 | |
146 */ | |
147 public static function getPreviousSibling(x:XML):XML | |
148 { | |
149 return XMLUtil.getSiblingByIndex(x, -1); | |
150 } | |
151 | |
152 protected static function getSiblingByIndex(x:XML, count:int):XML | |
153 { | |
154 var out:XML; | |
155 | |
156 try | |
157 { | |
158 out = x.parent().children()[x.childIndex() + count]; | |
159 } | |
160 catch(e:Error) | |
161 { | |
162 return null; | |
163 } | |
164 | |
165 return out; | |
166 } | |
167 } | |
168 } |