On January 27th, this site will be read-only as we migrate to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,620 Users
  • 2,269,768 Discussions


JavaME Internal DOM classes

2987002 Member Posts: 4
edited Jul 13, 2015 5:27AM in Java ME Embedded


I need to implement my own org.w3c.dom.Element class that later on is used as a node in a org.w3c.dom.Document instance.
My own element class essentially implements the required interface and everything works fine, at least in a Java standard edition.

Running it on a micro edition (v 8) I do see some unexpected behaviour. I get a class cast exception.

  - com/sun/ukit/dom/XParent.appendChild(), bci=21

Looking for the code I found the following on [1]

  public Node appendChild(Node newChild)
  throws DOMException
  if (_isRO())
  throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "");

  XNode nchild = (XNode)newChild;
  if (newChild.getNodeType() != DOCUMENT_FRAGMENT_NODE) {
  // Append a new child node.
  } else {
  // Recursive call to appendChild for each child of doc fragment
  while (nchild.getLength() > 0)
  return nchild;

It looks like each newChild node gets casted to XNode. First of all I wonder why and second I would like to know how I can now write my own Node classes. I cannot simply extend XNode given that it seems internal somehow.

Any ideas? Thank you very much for every hint,

-- Daniel

P.S: Sorry for cross posting the same question on JavaME Internal DOM classes (Java Micro Edition forum at JavaRanch)

[1] https://svn.java.net/svn/phoneme~svn/components/jsr280/branches/jsr280-cr-6781500/src/share/oi/com/sun/ukit/dom/XParent.java


  • Alexey Bakhtin-Oracle
    Alexey Bakhtin-Oracle Member Posts: 10
    edited Jul 9, 2015 10:03AM

    Hello Daniel,

    Unfortunately, current implementation of JavaME Embedded v8 does not support custom implementations of the org.w3c.dom.Element class.

    Could you attach an example of usage of your custom Element. I'll try to suggest workaround for your particular use-case.

    Thank you


  • 2987002
    2987002 Member Posts: 4
    edited Jul 13, 2015 5:27AM

    Hi Alexey,

    Thank you very much for your feedback.

    Let me try to explain our goal and maybe there is really a workaround. Would be great!

    The main idea is to create a lazy DOM, meaning that by default only a small portion of the DOM is loaded while the rest of the processing is postponed/skipped till it is really needed. The reason for that is that we cannot afford loading the entire DOM due to memory restrictions. Further, in our cases only a small portion is sufficient and other portions of the DOM are loaded (and later on also unloaded).

    Attached a snipped of  our SCElementMEncode that implements org.w3c.dom.Element. Each SCElementME knows its localName and its namespaceURI. If more information are needed the actual DOM portion needs to be loaded (see checkStatus() method). We make use of the EXI format (http://www.w3.org/TR/exi/) that allows us to to have random access into the XML document by means of selfContained EXI elements.

    I hope it is clear what we try to achieve and you can suggest a workaround.


    -- Daniel

    ------------- CODE

    public class SCElementME implements Element {


        final String namespaceURI;

        final String localName;

        final Document doc;


        final Element el;

        boolean loaded = false;


        public SCElementME(Document doc, String namespaceURI,

                String localName) {

            this.doc = doc;

            this.namespaceURI = namespaceURI;

            this.localName = localName;


            this.el = doc.createElementNS(namespaceURI, localName);



        protected void checkStatus() {

            if(!loaded) {

                // load EXI SC fragment into element el

                // ...

                this.el.appendChild(null); // TODO load children etc.


                loaded = true;



        public String getLocalName() {

            return this.localName;


        public String getNamespaceURI() {

            return this.namespaceURI;



        public NamedNodeMap getAttributes() {


            return el.getAttributes();


        public NodeList getChildNodes() {


            return el.getChildNodes();


        /////// .. more


This discussion has been closed.