The java.xml.direct.attribute option enables an interpreter facility for Relaxer objects.
The java.xml.direct.attribute option takes one of the following values as a parameter:
The default configuration is false
.
No parameter implies that the parameter is 'true
'.
The java.xml.direct.attribute option generates
no additional classes, but RelaxerOrg.jar
is needed
for the class library.
The java.xml.direct.attribute option adds the following methods to Relaxer objects.
rGetParentRNode()
rSetParentRNode(IRNode)
rGetRNodes()
Object eval()
Object eval(IREvaluationContext)
Object eval(Object[], IREvaluationContext)
The rGetParentRNode
mehtod,
the rSetParentRNode
method, and
the rGetRNodes
methods are derived
from the java.pattern.composite option.
Three eval
methods are methods for interpreter.(?)
List 4.22.3.1[javaXmlDirectAttribute.rng] is a sample schema for the java.xml.direct.attribute option.
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> <start> <ref name="account"/> </start> <define name="account"> <element name="account"> <attribute name="accountNo"> <data type="token"/> </attribute> <element name="balance"> <data type="int"/> </element> <element name="owner"> <data type="token"/> </element> <optional> <ref name="address"/> </optional> <zeroOrMore> <ref name="phone"/> </zeroOrMore> </element> </define> <define name="address"> <element name="address"> <attribute name="zip"> <data type="token"/> </attribute> <text/> </element> </define> <define name="phone"> <element name="phone"> <attribute name="area"> <data type="token"/> </attribute> <data type="token"/> </element> </define> </grammar>
Execution of Relaxer with the java.xml.direct.attribute option is as follows:
$ relaxer -java -java.xml.direct.attribute \ javaXmlDirectAttribute.rng
Because the Java generator is a default generator, execution of Relaxer as shown below has the same effect:
$ relaxer -java.xml.direct.attribute javaXmlDirectAttribute.rng
As a result, Relaxer generates six files:
List 4.22.3.1.1[JavaXmlDirectAttribute.java] is a sample program for the java.xml.direct.attribute option.
import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.SAXException; public class JavaXmlDirectAttribute { public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException { String uri = args[0]; Account account = makeAccount(uri); appendDirectAttribute(account); showDirectAttributes(account); printAccount(account); showAccount(account); } private static Account makeAccount(String uri) throws IOException, SAXException, ParserConfigurationException { System.out.println("*** makeAccount ***"); Account account = new Account(uri); return (account); } private static void printAccount(Account account) { System.out.println("*** printAccount ***"); String accountNo = account.getAccountNo(); long balance = account.getBalance(); String owner = account.getOwner(); System.out.println("AccountNo:" + accountNo); System.out.println("Balance:" + balance); System.out.println("Owner:" + owner); Address address = account.getAddress(); if (address != null) { String zip = address.getZip(); String place = address.getContent(); System.out.println("Address: [" + zip + "] " + place); } Phone[] phones = account.getPhone(); for (int i = 0;i < phones.length;i++) { Phone phone = phones[i]; String area = phone.getArea(); String number = phone.getContent(); System.out.println("Phone: [" + area + "] " + number); } } private static void showAccount(Account account) { System.out.println("*** showAccount ***"); System.out.println("XML:" + account); } private static void appendDirectAttribute(Account account) { System.out.println("*** appendDirectAttribute ***"); account.rSetAttribute("memo", "memo text"); } private static void showDirectAttributes(Account account) { System.out.println("*** showDirectAttributes ***"); String[] keys = account.rGetAttributeKeys(); for (int i = 0;i < keys.length;i++) { String key = keys[i]; String value = account.rGetAttribute(key); System.out.println(key + " = " + value); } } }
Compilation of JavaXmlDirectAttribute
class is shown here:
$ javac JavaXmlDirectAttribute.java
List 4.22.3.2.1[javaXmlDirectAttribute.xml] is an XML document for testing.
<account accountNo="12345" note="note text"> <balance>102030</balance> <owner>XML Taro</owner> <address zip="213">Yokohama</address> <phone area="123">456-7890</phone> <phone area="090">123-4567</phone> </account>
Execution of the JavaXmlDirectAttribute
class is shown here:
$ java JavaXmlDirectAttribute javaXmlDirectAttribute.xml