{"id":138,"date":"2008-12-29T09:27:35","date_gmt":"2008-12-29T16:27:35","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=435"},"modified":"2008-12-29T09:27:35","modified_gmt":"2008-12-29T16:27:35","slug":"e4x-filtering","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=138","title":{"rendered":"E4X Filtering"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar userInfo:XML = &lt;users&gt;\r\n  &lt;user fname=&quot;joe&quot; lname=&quot;smith&quot; age=&quot;31&quot; \/&gt;\r\n  &lt;user fname=&quot;mildred&quot; lname=&quot;calder&quot; age=&quot;64&quot; \/&gt;\r\n  &lt;user fname=&quot;ben&quot; lname=&quot;nathanson&quot; age=&quot;20&quot; \/&gt;\r\n  &lt;user fname=&quot;james&quot; lname=&quot;biuford&quot; age=&quot;19&quot; \/&gt;\r\n  &lt;user fname=&quot;nick&quot; lname=&quot;calhoun&quot; age=&quot;45&quot; \/&gt;\r\n&lt;\/users&gt;;\r\n\r\n\r\ntrace(&quot;Users over 20:n&quot;);\r\ntrace(userInfo.user.(@age &gt; 20).toXMLString());\r\n\r\ntrace(&quot;nUsers with the name nick:n&quot;);\r\ntrace(userInfo.user.(@fname == &quot;nick&quot; ).toXMLString());\r\n\r\n\/\/ use regular expressions with e4x\r\ntrace(&quot;nUsers with name starting with j:n&quot;);\r\ntrace(userInfo.user.(\/^j\/.test(@fname)));\r\n\r\n\/*\r\noutputs:\r\n\r\nUsers over 20:\r\n\r\n&lt;user fname=&quot;joe&quot; lname=&quot;smith&quot; age=&quot;31&quot;\/&gt;\r\n&lt;user fname=&quot;mildred&quot; lname=&quot;calder&quot; age=&quot;64&quot;\/&gt;\r\n&lt;user fname=&quot;nick&quot; lname=&quot;calhoun&quot; age=&quot;45&quot;\/&gt;\r\n\r\nUsers with the name nick:\r\n\r\n&lt;user fname=&quot;nick&quot; lname=&quot;calhoun&quot; age=&quot;45&quot;\/&gt;\r\n\r\nUsers with name starting with j:\r\n\r\n&lt;user fname=&quot;joe&quot; lname=&quot;smith&quot; age=&quot;31&quot;\/&gt;\r\n&lt;user fname=&quot;james&quot; lname=&quot;biuford&quot; age=&quot;19&quot;\/&gt;\r\n\r\n*\/\r\n<\/pre>\n<p>One of the nicest features of E4X is filtering. The above code shows a few simple examples &#8230; the last example makes use of regular expressions &#8212; I first read using regular expressions and E4X somewhere on <a href='http:\/\/www.darronschall.com\/' target='blank'>http:\/\/www.darronschall.com\/<\/a>.<\/p>\n<p>I usually prefer to use a database for any kind of info I&#8217;ll be searching&#8230; but if you know you have a relatively small amount of data XML can be a fine way to go.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var userInfo:XML = &lt;users&gt; &lt;user fname=&quot;joe&quot; lname=&quot;smith&quot; age=&quot;31&quot; \/&gt; &lt;user fname=&quot;mildred&quot; lname=&quot;calder&quot; age=&quot;64&quot; \/&gt; &lt;user fname=&quot;ben&quot; lname=&quot;nathanson&quot; age=&quot;20&quot; \/&gt; &lt;user fname=&quot;james&quot; lname=&quot;biuford&quot; age=&quot;19&quot; \/&gt; &lt;user fname=&quot;nick&quot; lname=&quot;calhoun&quot; age=&quot;45&quot; \/&gt; &lt;\/users&gt;; trace(&quot;Users over 20:n&quot;); trace(userInfo.user.(@age &gt; 20).toXMLString()); trace(&quot;nUsers with the name nick:n&quot;); trace(userInfo.user.(@fname == &quot;nick&quot; ).toXMLString()); \/\/ use regular expressions with e4x trace(&quot;nUsers with name starting [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[3,106,4,74,92],"class_list":["post-138","post","type-post","status-publish","format-standard","hentry","category-xml","tag-actionscript","tag-e4x","tag-flash","tag-regular-expressions","tag-xml"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}