Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I simulate w3c Dom API in Codenameone

Tags:

codenameone

I am trying to port CookXml to codenameone so I can use it to define UI in xml. CookXml depends on w3c dom and javax parser. I am looking for a way to replace the javax document builder class with the XMLParser in codenameone. I am stumped by the fact that even though XMLParser is supposed to be a close port I don't seem to be able to identify what to use to get attributes or the Attr node. Is the element in XMLParser the same as the Attr node? Or is it not just supported? How would I for instance be able to get names of attributes for an element?

like image 365
user1622343 Avatar asked Jan 27 '26 20:01

user1622343


1 Answers

XMLParser unified the concepts of Node, Document, Element etc. into a single Element class.

Attributes are simplified when compared to the DOM attributes.

To get the attributes you can just call:

Hashtable<String, String> h = (Hashtable<String, String>)elem.getAttributes();

Then to get all the attribute names/values:

for(String key : h.keySet()) {
    String value = h.get(key);
    ....
}
like image 113
Shai Almog Avatar answered Jan 31 '26 21:01

Shai Almog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!