How to Remove Default Attribute Values From the Output Java XML Transformer

The Java "Transformer" class converts the data you contain in your XML applications to an XLST format: a style sheet that sets up the layout for your XML data. The Transformer class is beneficial for Web developers who need to use the two formats together to create Web layouts. The Transformer class handles the format conversion, so you just need to initialize the class and set up the default attribute to remove it from the layout.

Instructions

    • 1

      Open the Java editor you use to create your applications. Open the project, and then double-click the Java source code file you want to use with the Transformer class.

    • 2

      Add the libraries to the top of the source code file. You must add the "includes" to use the libraries. The following code adds the includes to the source code:

      include javax.xml.transform;

    • 3

      Initialize the Java Transformer class. The following code code initializes the class:

      TransformerFactory trans = TransformerFactory.newInstance( );

    • 4

      Load the XLST file you want to use to transform the XML data. The following code loads a file named "styles.xlst":

      Transformer file = transFact.newTransformer("stles.xlst");

    • 5

      Remove the default attribute. You remove the default attribute by setting it to a blank string. The following code removes the attribute:

      file.setParameter("default", "");

    • 6

      Save the changes and click the "Run" button in the editor's toolbar to view the code changes in the debugger.

Related Searches:

References

Comments

Related Ads

Featured