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

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Adam Bosworth Article - what does "direct access" m ean?

[ Lists Home | Date Index | Thread Index ]

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@CS.UCLA.EDU]

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..





 

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

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