Here’s another issue I’m struggling with: The ECMA spec has an [[Insert]] and [[Replace]] internal method defined for XML.
Here’s the semantics for [[Insert]]: Semantics When the [[Insert]] method of an XML object x is called with property name P and value V, the following steps are taken: 1. If x.[[Class]] ∈ {"text", "comment", "processing-instruction", "attribute"}, return 2. Let i = ToUint32(P) 3. If (ToString(i) is not equal to P), throw a TypeError exception 4. If Type(V) is XML and (V is x or an ancestor of x) throw an Error exception 5. Let n = 1 6. If Type(V) is XMLList, let n = V.[[Length]] 7. If n == 0, Return 8. For j = x.[[Length]]-1 downto i, rename property ToString(j) of x to ToString(j + n) 9. Let x.[[Length]] = x.[[Length]] + n 10. If Type(V) is XMLList a. For j = 0 to V.[[Length-1]] i. V[j].[[Parent]] = x ii. x[i + j] = V[j] 11. Else a. Call the [[Replace]] method of x with arguments i and V 12. Return The [[Insert]] method is referenced a few places in the spec, but I’m really not sure how/why it’s defined as it is for XML objects (as opposed to XMLList objects). It kind of sounds like the contents of the XML object itself is redefined (as opposed to children). Why would you do that rather than [[Insert]] a child XML object into the parent and/or replace the child with a different one? If my reading is right, I have no clue how to read the spec for [[Put]], insertChildBefore, insertChildAfter and prependChild. All those cases seem to be adding children. Color me confused, Harbs On Jan 11, 2016, at 9:24 AM, Harbs <harbs.li...@gmail.com> wrote: > Thanks for that. > > So: It looks like all items in xml get the parent namespaces associated with > them as XML objects, but the namespaces are not written when using > toXMLString(). > > Transferring an element with a namespace to another xml element loses the > prefix and has an un-prefixed namespace applied to it. > If the uri exists in the new element with a prefix, the element takes on the > prefix of the new element. > > > On Jan 11, 2016, at 5:21 AM, Andy Dufilie <andy.dufi...@gmail.com> wrote: > >> On Sun, Jan 10, 2016 at 4:53 PM, Harbs <harbs.li...@gmail.com> wrote: >> >>> I’m trying to figure out namespace behavior. >>> >>> I’m probably tired, but can someone tell me why the “catalog_item” var in >>> this test (on line 70) does not get any results? >>> >>> https://gist.github.com/Harbs/c24285b3af80eeed251d >>> >> >> >> I put your code in an .as file instead of an .mxml, and it won't compile >> because of this line: >> >> var catalog_item = xml..fx::catalog_item[0]; >> 1120: Access of undefined property fx. >> >> I think it's only a warning in MXML ("*possibly* undefined property") >> because you've defined the fx namespace in the mxml tag at the top of the >> file. To fix it, you either need to add the following to your code inside >> CDATA: >> >> namespace fx = 'http://ns.adobe.com/mxml/2009'; >> >> or use one of these forms: >> >> var catalog_item = xml..('http://ns.adobe.com/mxml/2009')::catalog_item[0]; >> var catalog_item = xml.descendants(new QName('http://ns.adobe.com/mxml/2009', >> 'catalog_item'))[0]; >