Titanium JIRA Archive
Appcelerator Community (AC)

[AC-539] Titanium.XML: Can't get element by id if id property defined in uppercase

GitHub Issuen/a
ResolutionNeeds more info
Resolution Date2015-12-27T05:46:09.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
ReporterAndrey Tkachenko
AssigneeSharif AbuDarda


This code returns null:
Ti.XML.parseString(	'<node ID="ID_1302537637"></node>').getElementById('ID_1302537637')


  1. Sharif AbuDarda 2015-12-13

    Hello, In xml you can't define id peramiter in uppercase. It always supports lowecase. Appcelerator alloy dosen't recognise any element if it's id is define in all uppercase. In Alloy you can get id of an element of index.xml by "$.id" in index.js. For example:
       <Label id="label2" color="blue" textAlign="Ti.UI.TEXT_ALIGNMENT_LEFT" top="30" width="300" height="200">
       $.label2.color = "green" ;
    But, this will not work, When
       <Label ID="label2" color="blue" textAlign="Ti.UI.TEXT_ALIGNMENT_LEFT" top="30" width="300" height="200">
       $.label2.color = "green" ;
    Hope this clear your concept. Thanks.
  2. Andrey Tkachenko 2015-12-13

    Thx, how does this relate to the Alloy? I load a third-party file that has many attributes in uppercase. I can get uppercase attribute value but can't get element by id in uppercase.
  3. Andrey Tkachenko 2015-12-13

    As written in this documents [Document.getElementById](https://docs.oracle.com/javase/7/docs/api/org/w3c/dom/Document.html#getElementById%28java.lang.String%29) and [Attr.isId](https://docs.oracle.com/javase/7/docs/api/org/w3c/dom/Attr.html#isId%28%29) I can use *DTD* in order to define *id* as uppercase valid ID type attribute. But this code [XMLModule](https://github.com/appcelerator/titanium_mobile/blob/bc85170157d3bebc5de1d61a9fe6e34bce84a8c9/android/modules/xml/src/java/ti/modules/titanium/xml/XMLModule.java#L39) generates *DocumentBuilder* without *DTD* support. Need API to enable *DTD* validation through [DocumentBuilderFactory.setValidating(true)](https://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setValidating%28boolean%29) or other way.
  4. Sharif AbuDarda 2015-12-15

    Hello, getElementById, returns an Element that has an ID attribute with the given value. The Titanium.XML.Element represents an element in a DOM document, a [Titanium.XML.Node](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.XML.Node) defined by a start-tag and end-tag (or an empty tag). Elements may have attributes associated with them. Implements the [DOM Level 2 API](http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-745549614) on Android and iOS with some non-standard extensions. Exposes the [DOM Level 3 API](http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-745549614) implementation on Mobile Web. Note that HTML processors often perform specific case normalizations (canonicalization) of the markup before the DOM structures are built. This is typically using uppercase for element names and lowercase for attribute names. For this reason, applications should also compare element and attribute names returned by the DOM implementation in a case-insensitive manner. Hope this helps, Thanks.
  5. Andrey Tkachenko 2015-12-15

    How it can help me? I doing some replacement in source document before load it in parser. Not the best solution... I need some API for document normalization or/and DTD validation.
  6. Andrey Tkachenko 2015-12-15

    As it is written in http://stackoverflow.com/a/7466809/506724 How does the DOM know what attribute type an attribute has? There are three ways: * Provide an XML Schema to the parser * Provide a DTD to the parser * Explicitly indicate to the DOM that it is treated as an attribute type of ID.
  7. Sharif AbuDarda 2015-12-24

    Hello, Can you provide a full code and description of what you are trying to achieve. Provide a full test code which generates the issue. Also provide a full step to reporduce. Also please specify the full platform information node, java, SDK etc. Thanks.

JSON Source