[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?

  • To: 'Murali Mani' <mani@C...>
  • Subject: RE: Adam Bosworth Article - what does "direct access" m ean?
  • From: "Bullard, Claude L (Len)" <clbullar@i...>
  • Date: Thu, 16 Jan 2003 10:25:40 -0600
  • Cc: xml-dev@l...

ide direct access
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!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.