[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Adam Bosworth Article - what does "direct access" m ean?
See the article by Bosworth. It is tougher code to enter and read, and it is brittle given changes to the structure of a document. http://www.fawcette.com/xmlmag/2002_12/magazine/columns/endtag/ This: XML x = getxml("somewhere"); PERatio = x.price/( x.revenues - x.expenses); vs Tree t = ParseXML("somewhere"); PERatio = number(t.getmember( "/stock/price")) / (( number(t.getmember( "/stock/revenues") - number( t.getmember("/stock/expenses")) or XMLReader xmlreader = new SAXParser(); ContentHandler contentHandler = new MyContentHandler(); xmlreader.setContentHandler(contentHandler); String uri = "test.xml"; InputSource is = new InputSource( new FileInputStream(new File(uri))); xmlreader.parse(is); double result = contentHandler.getPERatio() plus his listing for the contentHandler class MyContentHandler implements ContentHandler { String clName; double num,price,revenue,expense; public void characters(char ac[], int start, int length) throws SAXException { String s = new String(ac,start,length); Try {if (!clName.equals("root")) num = Double.parseDouble(s);} catch(NumberFormatException e) {} if (clName.equals("Price"))price = num; if (clName.equals("Revenue"))revenue = num; if (clName.equals("Expense"))expense = num; } public void startElement( String nameSpaceURI, String localName, String rawName, Attributes attributes) throws SAXException { clName = localName; } public double getPERatio() { if (revenue != expenses) return ( price / (revenue - expenses) else return 0; } /** In addition, implement lots of dummy void methods for endDocument, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, endElement, and startPrefixMapping. **/ } And we won't even get into namespaces. :-) len From: Murali Mani [mailto:mani@C...] On Thu, 16 Jan 2003, Bullard, Claude L (Len) wrote: > XML-DEVers are often people with very large herds. > You can do what you want to the sacred cow, but > leave the productive milk cows alone. > > So you have alternatives. Let's hear about them. > I don't like writing XPaths either. > > len Hello, I did not know people did not like XPath expressions. can you tell me some important reasons why. I will argue why I like Xpath expressions..
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|