December 2009
November 2009
October 2009
September 2009
June 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
July 2008
June 2008
October 2007
September 2007
I have been using lxml to generate XML to interface with Authorize.net's CIM API and I noticed something. Element does not behave as expected, which is supposed to be as a list. The key difference is with references to the same Element.
1 2 3 4 5 6 7 8 | #!/usr/bin/env python from lxml import etree root = etree.Element('root') child = etree.Element('child') root.append(child) root.append(child) print etree.tostring(root, pretty_print=True) |
If you run this, you will get the following output:
<root> <child/> </root>
One child when we are expecting two. This is a bug. The workaround is to use deepcopy.
1 2 3 4 5 6 7 8 9 | #!/usr/bin/env python from copy import deepcopy from lxml import etree root = etree.Element('root') child = etree.Element('child') root.append(child) root.append(deepcopy(child)) print etree.tostring(root, pretty_print=True) |
This results with the expected output:
<root> <child/> <child/> </root>
Google has put a lot of work into their Android platform, but their non-Eclipse development instructions could use some work. Just trying to build their Hello, Android fails if you follow their notes to the letter. You'll get this error or similar:
[tlesmann@kimiko HelloAndroid]$ ant
Buildfile: build.xml
dirs:
[echo] Creating output directories if needed...
resource-src:
[echo] Generating R.java / Manifest.java from the resources...
aidl:
[echo] Compiling aidl files into Java classes...
compile:
[javac] Compiling 2 source files to /home/lethal/src/android/HelloAndroid/bin/classes
[javac] Compliance level '1.4' is incompatible with target level '1.5'. A compliance level '1.5' or better is required
BUILD FAILED
/home/tlesmann/src/android/HelloAndroid/build.xml:140: Compile failed; see the compiler error output for details.
Total time: 1 second
I was completely at a loss with this error and all the pages I found on Google were worthless. I'm hoping to change that with this post. The problem is that Sun's javac has a compliance level of 1.4 by default. This can be changed with a command-line argument of -1.5. To get ant to use this argument when compiling, you have to edit the build.xml like so:
<!-- Compile this project's .java files into .class files. --> <target name="compile" depends="dirs, resource-src, aidl"> <javac encoding="ascii" target="1.5" debug="true" extdirs="" srcdir="." destdir="${outdir-classes}" bootclasspath="${android-jar}"> <compilerarg value="-1.5"/> <classpath> <fileset dir="${external-libs}" includes="*.jar"/> </classpath> </javac> </target>
Add the line, <compilerarg value="-1.5"/>, within the javac element and ant will properly build the Hello, Android application. I'm surprised that the activitycreator program does not do this for you as Google advises you to use Sun's JDK.
I hope I've helped you avoid the frustration I suffered solving this silly issue.
NOTE: You no longer have to do this with the release of the 1.5 SDK! Just install Sun's Java and it will build without a problem.
