XML DOM setAttribute and createElement?

You must Login before you can answer or comment on any questions.

Does the XML DOM support node.setAttribute() and document.createElement?

Can't find any documentation on it.

There are some examples on the GitHub repository, but it doesn't show what I'm looking for.

2 Answers

Yes, it has that methods (I've been using them) and it should have all DOM 2 methods.

Hi,

I can't get createElement to work, I receive the following error:

[WARN] Exception in event callback. { expressionBeginOffset = 2173; expressionCaretOffset = 2193; expressionEndOffset = 2204; line = 5; message = "Result of expression 'xmlDOM.createElement' [undefined] is not a function."; name = TypeError; sourceId = 297969104; }

var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'readitems.xml');
var contents = f.read();
var xmlDOM = Titanium.XML.parseString(contents.text).documentElement;
 
var newel=xmlDOM.createElement("edition");
var newtext=xmlDOM.createTextNode("First");
newel.appendChild(newtext);
<?xml version="1.0" encoding="UTF-8"?>
<items>
    <item>
        This here item
    </item>
    <item>
        This other item
    </item>
 
</items>
Can anybody provide an example of createElement in action? I've searched EVERYWHERE! and I can't find anything...

Thanks!

Your Answer

Think you can help? Login to answer this question!