I figured out a way to determine XML “type” for “element” “text” and “attribute” without writing an instance variable at all.
I also discovered and fixed some issues with delete in the XML implementation. (I added tests for that.) Greg, thanks for all the tests! It makes fixing issues (and confirming fixes) much easier! ;-) Harbs > On Dec 18, 2019, at 9:48 PM, [email protected] wrote: > > This is an automated email from the ASF dual-hosted git repository. > > harbs pushed a commit to branch develop > in repository https://gitbox.apache.org/repos/asf/royale-asjs.git > > commit e4d1facc591c2a57d430878c78146a2760215032 > Author: Harbs <[email protected]> > AuthorDate: Wed Dec 18 21:45:47 2019 +0200 > > Fixed delete issues > Removed XMLText and XMLAttribute classes > --- > frameworks/projects/XML/src/main/royale/XML.as | 55 ++++++++++++++-------- > .../projects/XML/src/main/royale/XMLAttribute.as | 55 ---------------------- > frameworks/projects/XML/src/main/royale/XMLText.as | 55 ---------------------- > .../flexUnitTests/xml/XMLTesterGeneralTest.as | 4 ++ > 4 files changed, 40 insertions(+), 129 deletions(-) > > diff --git a/frameworks/projects/XML/src/main/royale/XML.as > b/frameworks/projects/XML/src/main/royale/XML.as > index 9df4b14..ccd283d 100644 > --- a/frameworks/projects/XML/src/main/royale/XML.as > +++ b/frameworks/projects/XML/src/main/royale/XML.as > @@ -324,7 +324,7 @@ package > > static private function insertAttribute(att:Attr,parent:XML):XML > { > - var xml:XML = new XMLAttribute(); > + var xml:XML = new XML(); > xml._parent = parent; > xml._name = getQName(att.localName, '', > att.namespaceURI, true); > xml._value = att.value; > @@ -407,12 +407,12 @@ package > data = data.trim(); > if (!data) return null; > } > - xml = new XMLText(); > + xml = new XML(); > xml.setValue(data); > break; > case 4: > //CDATA_SECTION_NODE > - xml = new XMLText(); > + xml = new XML(); > data = "<![CDATA[" + data + "]]>"; > xml.setValue(data); > break; > @@ -540,8 +540,6 @@ package > var className:String = > xml.ROYALE_CLASS_INFO.names[0].name; > switch(className){ > case "XML": > - case "XMLAttribute": > - case "XMLText": > return xml; > case "XMLList": > var xmlList:XMLList = xml as > XMLList; > @@ -572,7 +570,7 @@ package > var xmlStr:String = ignoreWhitespace ? > trimXMLWhitespace("" + xml) : "" + xml; > if(xmlStr.indexOf("<") == -1) > { > - _nodeKind = TEXT; > + // _nodeKind = TEXT; > _value = xmlStr; > } > else > @@ -581,7 +579,7 @@ package > } > } else { > if (!_internal) { > - _nodeKind = TEXT; > + // _nodeKind = TEXT; > _value = ''; > } > } > @@ -685,7 +683,7 @@ package > if (node.nodeType == 7) { > if > (XML.ignoreProcessingInstructions) { > if (!foundCount) { > - this._nodeKind > = TEXT; > + // > this._nodeKind = TEXT; > //e4x: The > value of the [[Name]] property is null if and only if the XML object > represents an XML comment or text node > delete > this._name; > > this.setValue(''); > @@ -698,7 +696,7 @@ package > } > } else if (node.nodeType == 4) { > if (!foundCount) { > - this._nodeKind = TEXT; > + // this._nodeKind = > TEXT; > //e4x: The value of the > [[Name]] property is null if and only if the XML object represents an XML > comment or text node > delete this._name; > > this.setValue('<![CDATA[' + node.nodeValue + ']]>'); > @@ -709,7 +707,7 @@ package > delete this._name; > if (XML.ignoreComments) { > if (!foundCount) { > - this._nodeKind > = TEXT; > + // > this._nodeKind = TEXT; > > this.setValue(''); > } > } else { > @@ -724,7 +722,8 @@ package > var whiteSpace:Boolean = > isWhitespace.test(node.nodeValue); > if (!whiteSpace || > !XML.ignoreWhitespace) { > if (!foundCount) { > - this._nodeKind > = TEXT; > + delete > this._name; > + // > this._nodeKind = TEXT; > > this.setValue(node.nodeValue); > } > foundCount++; > @@ -902,7 +901,7 @@ package > const wrapper:XML = new XML(); > wrapper.resetNodeKind(); > child = new XML(child.toString()); > - wrapper.setName(lastChild.name()); > + wrapper._name = lastChild._name; > child.setParent(wrapper); > wrapper.getChildren().push(child); > child = wrapper; > @@ -1165,7 +1164,7 @@ package > var xml:XML = new XML(); > xml.resetNodeKind(); > xml.setNodeKind(getNodeKindInternal()); > - xml.setName(name()); > + xml._name = _name; > if(_value){ > xml.setValue(_value); > } > @@ -1880,7 +1879,14 @@ package > } > > protected function getNodeRef():String{ > - return _nodeKind ? _nodeKind : ELEMENT; > + if(_nodeKind) > + return _nodeKind; > + if(!_name) > + return TEXT; > + if(_name.isAttribute){ > + return ATTRIBUTE; > + } > + return ELEMENT; > } > > private static const kindNameLookup:Object = { > @@ -1967,7 +1973,7 @@ package > private function xmlFromStringable(value:*):XML > { > var str:String = value.toString(); > - var xml:XML = new XMLText(); > + var xml:XML = new XML(); > xml.setValue(str); > return xml; > } > @@ -2060,16 +2066,26 @@ package > 7. Return true. > */ > var i:int; > + var len:int; > var removed:XML; > if(!child) > return false; > - > + if(child is XMLList){ > + var val:Boolean = false; > + len = child.length(); > + for(i=len-1;i>=0;i--){ > + if(removeChild(child[i])){ > + val = true; > + } > + } > + return val; > + } > if(!(child is XML)) > return removeChildByName(child); > > if(child.getNodeRef() == ATTRIBUTE) > { > - var len:int = attributeLength(); > + len = attributeLength(); > for(i=0;i<len;i++) > { > if(child.equals(_attributes[i])) > @@ -2397,8 +2413,9 @@ package > else > { > //it's a regular attribute string > - var attrXML:XML = new XMLAttribute(); > - attrXML.setName(toAttributeName(attr)); > + var attrXML:XML = new XML(); > + var nameRef:QName = toAttributeName(attr); > + attrXML._name = > getQName(nameRef.localName,nameRef.prefix,nameRef.uri,true); > attrXML.setValue(value); > len = attributeLength(); > for(i=0;i<len;i++) > diff --git a/frameworks/projects/XML/src/main/royale/XMLAttribute.as > b/frameworks/projects/XML/src/main/royale/XMLAttribute.as > deleted file mode 100644 > index 8a26c1f..0000000 > --- a/frameworks/projects/XML/src/main/royale/XMLAttribute.as > +++ /dev/null > @@ -1,55 +0,0 @@ > -//////////////////////////////////////////////////////////////////////////////// > -// > -// Licensed to the Apache Software Foundation (ASF) under one or more > -// contributor license agreements. See the NOTICE file distributed with > -// this work for additional information regarding copyright ownership. > -// The ASF licenses this file to You under the Apache License, Version 2.0 > -// (the "License"); you may not use this file except in compliance with > -// the License. You may obtain a copy of the License at > -// > -// http://www.apache.org/licenses/LICENSE-2.0 > -// > -// Unless required by applicable law or agreed to in writing, software > -// distributed under the License is distributed on an "AS IS" BASIS, > -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > -// See the License for the specific language governing permissions and > -// limitations under the License. > -// > -//////////////////////////////////////////////////////////////////////////////// > -package > -{ > - public class XMLAttribute extends XML > - { > - public function XMLAttribute() > - { > - super(); > - resetNodeKind(); > - } > - override protected function getNodeRef():String{ > - return "a"; > - } > - override public function copy():XML > - { > - var i:int; > - var xml:XML = new XMLAttribute(); > - xml.setName(name()); > - if(_value)xml.setValue(_value); > - > - var len:int; > - len = namespaceLength(); > - for(i=0;i<len;i++) > - { > - xml.addNamespace(new Namespace(_namespaces[i])); > - } > - //parent should be null by default > - len = attributeLength(); > - for(i=0;i<len;i++) > - xml.addChildInternal(_attributes[i].copy()); > - len = childrenLength(); > - for(i=0;i<len;i++) > - xml.addChildInternal(_children[i].copy()); > - > - return xml; > - } > - } > -} > \ No newline at end of file > diff --git a/frameworks/projects/XML/src/main/royale/XMLText.as > b/frameworks/projects/XML/src/main/royale/XMLText.as > deleted file mode 100644 > index a2f47ed..0000000 > --- a/frameworks/projects/XML/src/main/royale/XMLText.as > +++ /dev/null > @@ -1,55 +0,0 @@ > -//////////////////////////////////////////////////////////////////////////////// > -// > -// Licensed to the Apache Software Foundation (ASF) under one or more > -// contributor license agreements. See the NOTICE file distributed with > -// this work for additional information regarding copyright ownership. > -// The ASF licenses this file to You under the Apache License, Version 2.0 > -// (the "License"); you may not use this file except in compliance with > -// the License. You may obtain a copy of the License at > -// > -// http://www.apache.org/licenses/LICENSE-2.0 > -// > -// Unless required by applicable law or agreed to in writing, software > -// distributed under the License is distributed on an "AS IS" BASIS, > -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > -// See the License for the specific language governing permissions and > -// limitations under the License. > -// > -//////////////////////////////////////////////////////////////////////////////// > -package > -{ > - public class XMLText extends XML > - { > - public function XMLText() > - { > - super(); > - resetNodeKind(); > - } > - override protected function getNodeRef():String{ > - return "t"; > - } > - > - override public function copy():XML > - { > - var i:int; > - var xml:XML = new XMLText(); > - xml.setName(name()); > - if(_value)xml.setValue(_value); > - var len:int; > - len = namespaceLength(); > - for(i=0;i<len;i++) > - { > - xml.addNamespace(new Namespace(_namespaces[i])); > - } > - //parent should be null by default > - len = attributeLength(); > - for(i=0;i<len;i++) > - xml.addChildInternal(_attributes[i].copy()); > - len = childrenLength(); > - for(i=0;i<len;i++) > - xml.addChildInternal(_children[i].copy()); > - > - return xml; > - } > - } > -} > \ No newline at end of file > diff --git > a/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as > > b/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as > index 3affad8..2d3e57c 100644 > --- > a/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as > +++ > b/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as > @@ -1130,6 +1130,10 @@ package flexUnitTests.xml > assertEquals(xml.toString(),'<root><baz name="baz1"/><baz > name="baz2"/></root>',"name attribute should have been removed."); > delete xml.baz[0]; > assertEquals(xml.toString(),'<root><baz > name="baz2"/></root>',"the first baz element should have been removed."); > + xml = <root name="foo"><baz name="baz1"/><baz > name="baz2"/></root>; > + delete xml.baz; > + // delete xml.baz[0]; > + assertEquals(xml.toXMLString(),'<root name="foo"/>',"the first > baz element should have been removed."); > XML.setSettings(XML.defaultSettings()); > } > } >
