Displaying keyword search results 71 - 80
Created by Dr. Xi on April 26, 2011 20:12:01 Last update: April 28, 2011 15:28:12
An XML schema is a definition of XML files, in XML. It plays the same role as old-time DTDs. Overall, an XML schema file looks like this:
<schema attributeFormDefault = (qualified | u...The attribute meanings: targetNamespace : The name space targeted by the current schema definition. It can be any URI. id and version : For user convenience, the W3C spec defines no semantics for them. xml:lang : Natural language identifier defined by RFC 3306 . attributeFormDefault and elementFormDefault : Set default values for the form attribute for attribute and element declarations. blockDefault and finalDefault : Set default values for the block and final attributes for attribute and element declarations. The W3C defined some built-in datatypes . Examples of primitive datatypes are: string ,...
Created by Dr. Xi on April 27, 2011 11:26:54 Last update: April 27, 2011 11:27:13
DocumentBuilderFactory df = DocumentBuilderFactory...With Schema:
// Create schema SchemaFactory xsdFactory = Sch...With Relax NG:
// Create schema SchemaFactory xsdFactory = Sch...
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 Dr. Xi on April 27, 2011 08:28:31 Last update: April 27, 2011 08:37:40
JBoss example with hsql:
<persistence> <persistence-unit name="myapp"...MySQL example with JDBC :
<persistence xmlns="http://java.sun.com/xml...With OpenEJB transaction manager:
<persistence version="1.0" xmlns="...With EclipseLink :
<?xml version="1.0" encoding="UTF-8"?> <persist...
Created by freyo on April 21, 2011 11:08:05 Last update: April 21, 2011 11:08:05
In Android string resources, you can define a format string with placeholders instead of a static string, then use String.format() to render the string with runtime variable substitutions. For example ( res/values/strings.xml ):
<?xml version="1.0" encoding="utf-8"?> <resourc...In Java code:
String packageName = String.format(getString(R.str...
Created by freyo on April 18, 2011 15:08:21 Last update: April 18, 2011 15:12:20
Generate android project
$ ~/android-sdk-linux_86/tools/android create proj...Create XML file res/xml/books.xml :
<?xml version="1.0"?> <catalog> <book id=...Edit layout ( res/layout/main.xml ):
<?xml version="1.0" encoding="utf-8"?> <Lin...Edit code ( src/com/android/xmlres/XMLResource.java ):
package com.android.xmlres; import java.io....Change activity label from app_name to booklist ( AndroidManifest.xml ):
<?xml version="1.0" encoding="utf-8"?> <manifes...Add value for string resource ( res/values/string.xml ):
<?xml version="1.0" encoding="utf-8"?> <resourc...Deploy and test:
Created by freyo on April 18, 2011 14:14:29 Last update: April 18, 2011 14:15:48
For XML resources, Android returns an XmlPullParser reference. I tried the RSSReader example from xmlpull.org , it failed both on the Android emulator and with xpp3-1.1.4c . This is an example for XmlPullParser usage. Since the XmlPullParser is event based, a callback mechanism works better. Java code:
import java.io.*; import java.net.*; import ...The XML file used:
<?xml version="1.0" encoding="UTF-8"?> <catalog...
Created by freyo on April 15, 2011 09:00:54 Last update: April 15, 2011 09:00:54
Sample code for writing to a file in the internal storage. There are three steps: Open the file with Context.openFileOutput , which returns java.io.FileOutputStream . Write to the file. Close the file.
import java.io.*; import android.content.Contex...The second parameter to openFileOutput is the operating mode. Available values are: Context.MODE_PRIVATE Context.MODE_APPEND Context.MODE_WORLD_READABLE Context.MODE_WORLD_WRITEABLE The file is saved in /data/data/<package_name>/files .
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...