Recent Notes
Displaying keyword search results 1 - 10
Created by freyo on May 13, 2011 15:45:29
Last update: September 20, 2011 08:08:12
This is an Android app that dumps any binarized xml file as plain text - to the sdcard on the device or emulator.
build.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project...
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<man...
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<Lin...
res/values/strings.xml :
<?xml version="1.0" encoding="utf-8"?>
<res...
src/com/android/xmltool/DumpXml.java
package com.android.xmltool;
import java.ut...
Screenshot
Pre-built APK can be downloaded from: http://code.google.com/p/android-binxml-dump/
Created by alfa on June 03, 2011 12:36:14
Last update: June 03, 2011 12:36:14
Thread local storage is typically used to associate state with a thread (e.g., a user ID or Transaction ID). This example, coming from Java API doc , assigns a unique id to each thread that calls getCurrentThreadId() . The actual usage is demonstrated with the Java concurrency package.
import java.util.concurrent.Future;
import java...
Created by freyo on May 23, 2011 14:30:18
Last update: May 23, 2011 14:31:08
There are two distinct ways to process XPath: with namespace and without namespace. The code is different depending on whether the parser is namespace aware.
Code without namespace:
import java.io.*;
import javax.xml.parsers.*;
...
code with namespace:
import java.io.*;
import java.util.Iterator;
...
XML without namespace:
<?xml version="1.0" encoding="UTF-8" standalone="n...
XML with namespace:
<?xml version="1.0" encoding="UTF-8" standalone="n...
The same XPath expression works for both XML files when the parser is not namespace aware.
When the parser is namespace aware, you have to adjust the XPath accordingly depending on whether the XML has namespace declarations: " /test-license/licensee/name/text() " works for the XML file without namespace, while " /p:test-license/p:licensee/p:name/text() " works for the XML file with namespace.
Created by freyo on May 20, 2011 09:25:20
Last update: May 23, 2011 12:11:42
The javax.xml.crypto and javax.xml.crypto.dsig packages are not available in Android (as of version 2.3). Therefore, standard Java API does not work. But you can use the Apache Santuario library to do that. Here are the steps:
Download the xml security source distribution (curently version 1.4.4).
Build with ant.
Create your own library jar (only the apache classes, no javax):
jar -cf xmlsec-1.4.4.jar -C build/classes org
Copy xmlsec-1.4.4.jar to the libs directory of your Android project.
Here's the Java code:
import java.io.*;
import javax.xml.parsers.*;
...
Created by Dr. Xi on April 26, 2011 21:25:55
Last update: April 27, 2011 11:08:57
The following code validates a web.xml file against the web-app 2.5 schema:
// Java XML validation with schema
import java....
web.xml used for testing:
<?xml version="1.0" encoding="UTF-8"?>
<web-ap...
According to Java API doc , validation can also be done while parsing by calling setSchema on the parsing factory. However, validation doesn't work for the SAXParserFactory!
// Java XML validation with schema
import java....
Created by freyo on April 12, 2011 13:05:33
Last update: April 12, 2011 13:06:26
android:sharedUserId (from Android doc):
The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that they are also signed by the same certificate. Application with the same user ID can access each other's data and, if desired, run in the same process.
Declare sharedUserId in AndroidManifest.xml :
<manifest xmlns:android="http://schemas.android.co...
Retrieve sharedUserId programmatically:
import android.content.pm.PackageManager;
impor...
Created by nogeek on April 07, 2011 21:30:54
Last update: April 07, 2011 21:30:54
This is the opposite of parsing. You can use javax.xml.transform.Transformer to output a DOM tree to a file.
import java.io.*;
import javax.xml.parsers.Docu...
Created by nogeek on April 07, 2011 21:07:55
Last update: April 07, 2011 21:07:55
You can use the javax.xml.transform.Transformer class to "transform" an XML stream (string in this case) to a DOM tree - effectively parsing the XML string.
import java.io.*;
import javax.xml.transform.Tr...
Created by nogeek on April 07, 2011 20:54:17
Last update: April 07, 2011 20:54:17
Use javax.xml.parsers.DocumentBuilder to parse xml. DocumentBuilder.parse() takes:
java.io.File
org.xml.sax.InputSource
java.io.InputStream
java.lang.String as a URI to an XML document
Example code:
import java.io.*;
import javax.xml.parsers.Docu...
Created by nogeek on February 08, 2011 13:46:18
Last update: February 08, 2011 13:46:18
Simple Java code that does XSLT on an XML file. The transform results go to STDOUT.
import java.io.*;
import javax.xml.parsers....