OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   XML data support

[ Lists Home | Date Index | Thread Index ]
  • From: "Ian Molesworth" <ian@imolesworth.demon.co.uk>
  • To: <xml-dev@ic.ac.uk>
  • Date: Sun, 22 Aug 1999 15:52:05 +0100

Hi All
 
I have a suite of Java classes for working with well formed XML in memory. The idea is to enable applets running in browsers access to XML based data. I am currently passing data to applets in XMLObject form, I am also using these classes for the middleware layer in fairly large business critical applications.
 
Why re-invent the wheel? Well the .Jar file is 25k zipped. 30k unzipped. The raw class files run to about 65k, I have not tried to compress or optimise this yet. Any exceptions still print debug style messages to assist in fixing any problems. Compared to the 'full monty' applications from IBM and Microsoft' I reckon thats good enough reason.
 
The classes provide the following functionality -
 
create a new empty XmlObject
create an XmlObject from a string. ( or text file )
get the value of an attribute
set the value of an attribute
insert an attribute or node
remove an attribute or node
insert a copy of an XmlObject into another XmlObject
copy the XmlObject or a subsection of the XmlObject
build a cursor on a list of attributes at a certain level in the XmlObject
 
nodes and leaves can be located using qualified names. (IE: get ("customer.address.postcode") )
 
Anyway that's the basics, there are a few more besides. Are there any souls out there interested in  testing this lot before I let it loose on the general community? drop me a mail at ian@imolesworth.demon.co.uk and I'll mail you the files and some documentation.
 
Ian Molesworth
Tango4 Consulting ltd
+44 (0) 411 378 562
+44 (0) 1892 852846
 
Sample follows -
 
public static void main(java.lang.String[] args) {

 try
  {
  // To build an object from the test file uncomment the following line and
  // comment out the 4 after that
//  XmlObject theObject = XmlObject.createFromFile ("C:\\data\\testdata.xob");
 
  String theString = "<XmlStringUser><UserId>  12345 </UserId> <UserName> Ian Molesworth";
  theString   += "</UserName> <ProductList> <Product> <name> Term life </name> </Product> <Product>";
  theString     += "<name> dual life </name> </Product> <Product> <name> mortgage life </name> </Product>";
  theString       += "<Product> <name> annuity </name> </Product> </ProductList> </XmlStringUser>";
 
// Uncomment the next two lines to see the sample string streamed out
//  System.out.println("A string that will become an XmlObject - ");
//  System.out.println(theString);
  
  XmlObject theObject = XmlObject.buildFromString (theString);
 
// Uncomment the next two lines to see the formatted XML Object after being built from the string
//  System.out.println("\nThe serialized & formatted XmlObject - ");
//  System.out.println (theObject.asXml());
 
  theObject.insert ("Request","VerifyUser");
    
  XmlObject Address = XmlObject.build ("Address");
 
  Address.insert ("PostCode");
  Address.insert ("NameBer","31");
   Address.insert ("line4","East Sussex");
  theObject.insert (Address);
 
     theObject.set ("Address.PostCode","TN6 3LW");
 
// Uncomment the next two lines to see the formatted XML Object after being having the additional bits added.
//  System.out.println("\nThe NEW serialized & formatted XmlObject - ");
//     System.out.println (theObject.asXml());
      
  if ( theObject.contains("UserId"))
   {
   System.out.println ( "UserId      = " + theObject.get("UserId").asXml());
   System.out.println ( "User name   = " + theObject.get("UserName").asXml());
   if ( theObject.contains("ProductList"))
    {
       System.out.println ("List of products - ");
       int n = 1;
    // This bit pulls out a copy of the subsection ( class ) held under productlist
    XmlObject ListOfProducts = theObject.get("ProductList");
    // build a cursor on the enclosed attributes
    XCursor cursor =  new XCursor (ListOfProducts);
    
    while (cursor.hasMoreElements())
     {
     XmlObject listObject = (XmlObject)cursor.nextElement();
     System.out.println (n++ + " " + listObject.get("name").asXml());
     }     
    }
   else if ( theObject.contains("Product"))
    {
    System.out.println (theObject.get("Product.name").asXml());
    }
   }
  }
  
 catch ( Throwable exception )
  {
  System.out.println ("Exception........." + exception.getMessage());
  }
 
 }
 




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS