English 中文(简体)
甲型六氯环己烷
原标题:Android xml cloneNode
  • 时间:2011-11-17 10:36:27
  •  标签:
  • android
  • xml

彩色(Node)方法似乎是一种 b。 当我称之为这一方法时,我收到了一部“NAMESPACE_ERR”的DOMException鞭".。

我的法典如下:

DocumentBuilder builder= DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
Node n1 = doc.createElement("node");
Node n2 = n1.cloneNode(true);

任何想法? 事先感谢你!

EDIT : Important note : this code works perfectly if I run it on my computer with the Java JRE. It only fails on Android (1.6 and 2.2)

EDIT2 :并在Andrid 3.1 开展工作。 但我需要使用2.2版。 是否有工作?


Ok, I found a related bug : http://code.google.com/p/android/issues/detail?id=2735

but now I need a workaround... any idea ? NB : i don t want to add namespace to the created nodes.

问题回答

I tried this code and seems to work fine. I got the following in the Log

11-17 16:51:54.942: I/(15474): org.apache.harmony.xml.dom.ElementImpl@41413f88
11-17 16:51:54.942: I/(15474): org.apache.harmony.xml.dom.ElementImpl@41414040


Code

button1.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
    javax.xml.parsers.DocumentBuilder builder = null;
    try {
        builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        Log.e("","exception,e");
    }
    Document doc = ((javax.xml.parsers.DocumentBuilder) builder).newDocument();
    Node n1 = doc.createElement("node");
    Node n2 = n1.cloneNode(true);
        Log.i("",n1.toString());
        Log.i("",n2.toString());

}
});




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签