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 ]


Let me try to understand. Suppose you already have context node, then
XPath is easy, right? you can say for example, x.price/(x.revenues -
x.expenses) -- the problem seems to be when you have to set the context
node by parsing a document or you have to write your own SAX Handler? this
happens when you want some information from large numbers of documents..??

Let us look at it abstractly. From database perspective:

XML allows modeling of relationships using hierarchy, using ID-IDREF etc,
both of which can be traversed using path expressions, which is easier,
than using joins.

for example, consider relations
student (name, since, pname) and professor (pname, age)

you model in xml as professor (pname, age, student (name, since)*)

now to retrieve say students of professor X, you write
professor [pname="X"]/student

and to retrieve advisor of student Y, you write
professor [/student/name="Y"]

this will require joins and queries (at least slightly bigger) in
relational. there are too many scenarios when relational might make the
queries really awkward and difficult to write w/o making mistakes.

I will contend that XML makes it "easier" to model - more intuitive to
traverse and understand and also easier to write queries (as path
expressions)..

question of brittleness: Yes, the main principle on which relational DB is
based on is that queries need not change unless the logical structure
(rather external structure) changes. The same thing holds for XML also.
Queries will change if the XML Schema changes.

In short my contention is: XML does impose a hierarchical view for data. I
think it is for the better.

On Thu, 16 Jan 2003, Bullard, Claude L (Len) wrote:

> 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