Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid 1.5 and dom4j - attributes names parsed incorrectly
    primarykey
    data
    text
    <p>I am working on application for Android 1.5 . Currently, I need to parse XML file. As Android does not support XPath natively in API Level 3, I decided to use dom4j and jaxen libraries to read a file.</p> <p>I have simple XML file (test1.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;tests&gt; &lt;resources base_lang="en"&gt; &lt;string base="example"&gt; &lt;localization lang="pl"&gt;Przykład&lt;/localization&gt; &lt;/string&gt; &lt;/resources&gt; &lt;test name="main name"&gt; &lt;title&gt;Main Title&lt;/title&gt; &lt;description&gt;Long description&lt;/description&gt; &lt;/test&gt; &lt;/tests&gt; </code></pre> <p>And simple code:</p> <pre><code>SAXReader reader = new SAXReader(); Document doc = reader.read("file:///sdcard/tests/test1.xml"); Node node = doc.selectSingleNode("/tests/test"); Element elem = (Element)node; for(int j=0;j&lt;elem.attributeCount();++j) { Attribute attr = elem.attribute(j); Logger.getLogger(AutoTesterMain.class.getName()).log(Level.SEVERE, "ATTR: "+attr.getName()+"="+attr.getValue()); } </code></pre> <p>It reads test1.xml file, finds "/tests/test" node and enumerates it's attributes. When I run this code as part of "desktop" java application (I'm not deep in the java terminology), it displays what I expect (OpenJDK 1.8.3 under Fedora Linux):</p> <pre><code>SEVERE: ATTR: name=main name </code></pre> <p>Unfortunately, in Android 1.5 (emulator ofc), the exact same code shows:</p> <pre><code>E/AutoTesterMain( 823): ATTR: base_lang=main name </code></pre> <p>As you can see, attribute's value is OK, but there's problem with name. I have completely no idea, why in this place appears name of attribute from completely other DOM element ("/tests/resources"). It seems to parse my file incorrectly, so I probably set something wrong ...</p> <p>Of course both versions uses the exact same .jars with dom4j and jaxen libraries, so this is probably ok.</p> <p>This problem has more effects than only incorrect attributes listing. It also disallows me to read attributes properly using XPath - selection "/tests/test/@name" gives nothing, while "/tests/test/@base_lang" gives me "main name" string. This is obviously caused by the same error as in listing attributes above.</p> <p>Does anyone encountered this? How could I fix it?</p> <p>Moving to newer Android with native XPath support is unfortunately not an option for me.</p> <p>I was trying to find anything on web and here, but had no luck.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload