Portlet Factory, Version 6.1.2
About creating XML structures
To create XML structures, use the XMLUtil class methods create(), parseXml(), and parseHtml(). Alternatively, you can create a new XML structure by making a copy of an existing XML structure with the IXml().clone() method. You can create an empty structure when you are trying to build up a new XML structure based on form inputs, or any other time you want to create a structure before you populate it with elements. Use the XmlUtil.create() method, as shown in the following code:
IXml myIXml = XmlUtil.create("Customers");If you examine the myIXml object in the debugger, you see its structure consists of the following tag:<Customers />Otherwise, you can read in a file or string and create an IXML structure from it with the following code. For a string argument, use the XmlUtil.parseXml() method.
- From an XML file
IXml myIXml=null; try { FileReader fr = new FileReader(pathVar + "file.xml"); BufferedReader br = new BufferedReader(fr); myIXml = XmlUtil.parseXml(br); catch (IOException ioe) { System.out.println(ioe+"Cannot find file."); catch (com.bowstreet.util.parser.ParserException pe) { System.out.println(pe+"Cannot parse file."); }- From an HTML file
IXml myIXml=null; try { FileReader fr = new FileReader(pathVar + "file.html"); BufferedReader br = new BufferedReader(fr); myIXml = XmlUtil.parseHtml(br); catch (IOException ioe) { System.out.println(ioe+"Cannot find file."); catch (com.bowstreet.util.parser.ParserException pe) { System.out.println(pe+"Cannot parse file."); }- From a string
IXml myIXml = XmlUtil.parseXml("<Customers><Customer><Name>Jina</Name></Customer></Customers>");
Parent topic: Overview: working with XML
- About adding elements to an IXml structure
You can add elements to an IXml structure by retrieving the node to which you want to add an element and calling one of the following IXml methods.
- About iterating over elements in an IXML structure
You can iterate over a number of child elements, processing each element with code similar to the following:
- About modifying elements in an IXml structure
You can modify an element in an IXml structure by changing its name, text value, or by adding attributes and setting attribute values. Use the following methods to perform these tasks.
- About removing elements from an IXml structure
You can remove elements from an IXml structure by calling one of these methods.
- About processing XML with IXml
Most objects that you work with in IBM WebSphere Portlet Factory represent, or interact with, an XML structure.
Library | Support |