java left logo
java middle logo
java right logo
 

Home arrow Other API Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4089
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use XmlProperty task E-mail
User Rating: / 12
PoorBest 

XmlProperty

Description

Loads property values from a well-formed xml file. There are no other restrictions than "well-formed". You can choose the layout you want. For example this XML property file:

  <root>

    <properties>
      <foo>bar</foo>
    </properties>
  </root>
is roughly equivalent to this Java property file:

  root.properties.foo = bar

By default, this load does no processing of the input. In particular, unlike the Property task, property references (i.e., ${foo}) are not resolved.

Semantic Attributes

Input processing can be enabled by using the semanticAttributes attribute. If this attribute is set to true (its default is false), the following processing occurs as the input XML file is loaded:
  • Property references are resolved.
  • The following attriubtes are treated differently:
    • id: The property is associated with the given id value.
    • location: The property is treated as a file location
    • refid: The property is set to the value of the referenced property.
    • value: The property is set to the value indicated.
  • Path-like Structures can be defined by use of the following attributes:
    • pathid: The given id is used to identify a path. The nested XML tag name is ignored. Child elements can be used (XML tag names are ignored) to identify elements of the path.

For example, with semantic attribute processing enabled, this XML property file:

  <root>
    <properties>
      <foo location="bar"/>
      <quux>${root.properties.foo}</quux>
    </properties>

  </root>
is roughly equivalent to the following fragments in a build.xml file:
  <property name="root.properties.foo" location="bar"/>
  <property name="root.properties.quux" value="${root.properties.foo}"/>

Parameters

Attribute Description Required
file The XML file to parse. Yes
prefix The prefix to prepend to each property No
keepRoot Keep the xml root tag as the first value in the property name. No, default is true.
validate Validate the input file (e.g. by a DTD). Otherwise the XML must only be well-formed. No, default is false.
collapseAttributes Treat attributes as nested elements. No, default is false.
semanticAttributes Enable special handling of certain attribute names. See the Semantic Attributes section for more information. No, default is false.
includeSemanticAttribute Include the semantic attribute name as part of the property name. Ignored if semanticAttributes is not set to true. See the Semantic Attributes section for more information. No, default is false.
rootDirectory The directory to use for resolving file references. Ignored if semanticAttributes is not set to true. No, default is ${basedir}.

Nested Elements

xmlcatalog

The <xmlcatalog> element is used to perform entity resolution.

Examples

Non-semantic Attributes

Here is an example xml file that does not have any semantic attributes.

   <root-tag myattr="true">
    <inner-tag someattr="val">Text</inner-tag>

    <a2><a3><a4>false</a4></a3></a2>
   </root-tag>
default loading

This entry in a build file:

   <xmlproperty file="somefile.xml"/>
is equivalent to the following properties:
   root-tag(myattr)=true
   root-tag.inner-tag=Text
   root-tag.inner-tag(someattr)=val
   root-tag.a2.a3.a4=false
collapseAttributes=false

This entry in a build file:

   <xmlproperty file="somefile.xml" collapseAttributes="true"/>
is equivalent to the following properties:

   root-tag.myattr=true
   root-tag.inner-tag=Text
   root-tag.inner-tag.someatt=val
   root-tag.a2.a3.a4=false
keepRoot=false

This entry in a build file:

   <xmlproperty file="somefile.xml" keepRoot="false"/>
is equivalent to the following properties:
   inner-tag=Text
   inner-tag(someattr)=val
   a2.a3.a4=false

Semantic Attributes

Here is an example xml file that has semantic attributes.

  <root-tag>
    <version value="0.0.1"/>
    <build folder="build">
      <classes id="build.classes" location="${build.folder}/classes"/>
      <reference refid="build.classes"/>

    </build>
    <compile>
      <classpath pathid="compile.classpath">
        <pathelement location="${build.classes}"/>
      </classpath>
    </compile>

    <run-time>
      <jars>*.jar</jars>
      <classpath pathid="run-time.classpath">
        <path refid="compile.classpath"/>
        <pathelement path="${run-time.jars}"/>

      </classpath>
    </run-time>
  </root-tag>
default loading (semanticAttributes=true)

This entry in a build file:

   <xmlproperty file="somefile.xml"
                semanticAttributes="true"/>
is equivalent to the following entries in a build file:
  <property name="version" value="0.0.1"/>
  <property name="build.folder" value="build"/>
  <property name="build.classes" location="${build.folder}/classes" 
   id="build.classes"/>
  <property name="build.reference" refid="build.classes"/>

  <property name="run-time.jars" value="*.jar/>

  <classpath id="compile.classpath">
    <pathelement location="${build.classes}"/>
  </classpath>

  <classpath id="run-time.classpath">
    <path refid="compile.classpath"/>

    <pathelement path="${run-time.jars}"/>
  </classpath>
includeSemanticAttribute="true"

This entry in a build file:

   <xmlproperty file="somefile.xml"
                semanticAttributes="true"
                includeSemanticAttribute="true"/>
is equivalent to the following entries in a build file:

  <property name="version.value" value="0.0.1"/>
  <property name="build.folder" value="build"/>
  <property name="build.classes.location" location="${build.folder}/classes"/>
  <property name="build.reference.refid" refid="build.location"/>

  <property name="run-time.jars" value="*.jar/>

  <classpath id="compile.classpath">
    <pathelement location="${build.classes}"/>
  </classpath>

  <classpath id="run-time.classpath">
    <path refid="compile.classpath"/>
    <pathelement path="${run-time.jars}"/>

  </classpath>

Source: Apache Ant


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.