Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6853] iOS: xml attributes broken in 1.8.0.1

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionWon't Fix
Resolution Date2012-02-14T23:43:40.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterMauro Parra-Miranda
AssigneeStephen Tramer
Created2011-12-22T15:02:05.000+0000
Updated2012-02-14T23:43:40.000+0000

Description

PROBLEM DESCRIPTION

Code that was working up to recent CI build is now failing when querying xml attributes from an xml node.

STEPS TO REPRODUCE

1. Create new mobile project 2. Paste below code into the app.js 3. Run

ACTUAL RESULTS

[INFO] Attributes: null

EXPECTED RESULTS

[INFO] Attributes: [object TiDOMNamedNodeMap] [INFO] Value: appcelerator

CODE

var str = "<test name='appcelerator'/>";
var xml = Ti.XML.parseString(str); 
Ti.API.info("Attributes: "+xml.attributes); 
if (xml.attributes && (xml.attributes.length > 0)) { 
       Ti.API.info(" Value: "+xml.attributes.item(0).nodeValue); 
} 
win = Ti.UI.createWindow();
win.open(); 

WORKAROUND

A workaround was provided, and rejected from the customer.
var str = "<test name='appcelerator'/>" 
var xml = Ti.XML.parseString(str); 
var node = xml.documentElement;
//Ti.API.info("Attributes: "+xml.attributes); 
if (node.attributes && (node.attributes.length > 0)) { 
   Ti.API.info(" Value: "+node.attributes.item(0).nodeValue); 
};

win = Ti.UI.createWindow();
win.open(); 

Comments

  1. Stephen Tramer 2011-12-29

    This change is to conform to the DOM LEVEL 2 spec. See the description of "Attr": http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-637646024 And the IDL definition for "Document": http://www.w3.org/TR/DOM-Level-2-Core/core.html#i-Document In particular: * A Document is not an Element * Document provides the documentElement accessor for the element representing the root node of the document (the document object's first child) In the event that it was expected that you could directly access Element information off of a Document, this would require that we implement all Element methods on a Document (to conform to expected behavior, being able to retrieve Attr nodes off an object implies it is an Element, and that it should be interacted with as one). This violates the IDL specification by re-typing Document as a subtype of Element. The "workaround" is actually the correct way to interact with an XML tree.
  2. Stephen Tramer 2011-12-29

    Additionally, see the behavior definition for Node.attributes in this section of the spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247 The property is defined, but MUST (according to spec) return null for non-Element nodes.
  3. Thomas Huelbert 2012-01-23

    Closing based on Stevens comments

JSON Source