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

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: tree with xml



Hi,
A parser (such as SAX) on it's own doesn't provide a tree structure - you
either have to build one yourself, or use DOM.

I've recently worked on something along the lines of your example - walking
a directory tree and outputting the structure as XML. I managed this by
generating events from the (recursive) tree walker when new files and
directories were encountered. These events called methods that added
children to the DOM tree - I used a stack to remember the depth of directory
nesting, necessary because the data coming in was effectively a serial
stream. Putting tree structures into DOM is usually a lot more
straightforward than this. Likewise, the methods of the Element and Node
classes allow you to query the tree in a relatively direct fashion.

I've not got around to looking at PHP yet, but there's an awful lot of
XML/Java material available on the web - try a search on 'SAX DOM' or just
'JAXP'. For practical questions in this field your best bet is probably
Sun's XML-INTEREST list (see below) rather than this one - I'm sure you've
noticed the stuff here isn't exactly beginner friendly, even if you have an
W3C-English dictionary.

Cheers,
Danny.

xml-interest: A list for discussing XML technologies in the Java Platform.
To post, mailto:xml-interest@java.sun.com
Archives at: http://archives.java.sun.com/xml-interest.html
To unsubscribe, mailto:listserv@java.sun.com the following message;
signoff xml-interest.

I think to subscribe it's the same address as unsubscribe, but with the
message 'subscribe xml-interest' instead


<- -----Original Message-----
<- From: greg@circacipher.com [mailto:greg@circacipher.com]
<- Sent: 13 February 2001 06:18
<- To: Mike Brown
<- Cc: xml-dev@lists.xml.org
<- Subject: Re: tree with xml
<-
<-
<- Hi,
<-
<- Thanks for our answer, i tought noone would :-)
<- In the mean time, i browsed through websites and some doc, and
<- had already
<- understood what you explained to me.
<- And i've also tried to mess out a little bit with java and php and an xml
<- file of mine.
<- It seemed to work ok, except when i tried to do what i wanted to
<- do in the
<- first place
<- Something like reproducing a file/directory hierarchy
<- like
<- <folder name="root">
<-     <file>
<-         <type>doc</type>
<-         <filename>mytest</filename>
<-         <last-visited-date>011201</last-visited-date>
<-     </file>
<-     <file>
<-         <type>doc</type>
<-         <filename>mytest2</filename>
<-         <last-visited-date>011201</last-visited-date>
<-     </file>
<-     <folder name="subdir-test">
<-         <file>
<-             <type>doc</type>
<-             <filename>mytest-insubdir</filename>
<-             <last-visited-date>011201</last-visited-date>
<-         </file>
<-         <folder name="subsubdir">
<-             <file>
<-                 <type>doc</type>
<-                 <filename>subsubdir-testfile</filename>
<-                 <last-visited-date>011201</last-visited-date>
<-             </file>
<-         </folder>
<-     </folder>
<- </folder>
<-
<- See what i mean? The parser i used seemed not the 'see' the
<- <file>'s inside
<- the <folder>'s, and i didn't really understand what and how to do, so i
<- decided to ask the mailing list...
<- So maybe you can point me to some more precise doc, or book ?
<-
<- Thanks anyway
<-
<- greg
<-
<-
<- ----- Message d'origine -----
<- De : "Mike Brown" <mbrown@webb.net>
<- À : <greg@circacipher.com>
<- Cc : <xml-dev@lists.xml.org>
<- Envoyé : mardi 13 février 2001 0:59
<- Objet : RE: tree with xml
<-
<-
<- > > It's probably a stupid-beginner question, but i'm wondering
<- > > weither its possible to have simple tree (hierarchy, like
<- > > files and directories ie) utilisation of XML?
<- >
<- > Hmm, definitely a beginner question, but not stupid, considering how
<- > obtusely organized and not-for-the-layman the XML spec is.
<- >
<- > You will be happy to learn that XML is a linear syntax for the
<- > representation of a hierarchical data structure.
<- >
<- > A very simplistic view, to get you started, is that the data being
<- > represented is divided into segments of character data (text
<- strings) and
<- > nested abstract containers called elements. Elements have names (types,
<- > rather). An XML document has just one element at the top level, and the
<- tree
<- > forms 'below' that. Elements can have associated with them name-value
<- pairs
<- > called attributes. Attribute values are typically more character data.
<- >
<- > The XML syntax uses markup called tags to indicate element
<- boundaries and
<- > their attributes. Here is an example of the fundamental syntax:
<- >
<- > <greeting xml:lang="en">hello</greeting>
<- >
<- > This markup represents an element of type 'greeting' with the character
<- data
<- > contents 'hello'. The element has an attribute named 'xml:lang' with a
<- value
<- > of 'en'. Please do not confuse the physical markup ("tags") with the
<- > abstract, logical structures ("elements").
<- >
<- > OK, now we'll make that particular 'greeting' element be a child of a
<- > 'mydoc' element, and we give the greeting element some
<- siblings that are
<- > empty (content-free) 'foo' elements, demonstrating the two
<- different ways
<- > allowed to write an empty element:
<- >
<- > <mydoc><foo></foo><greeting
<- xml:lang="en">hello</greeting><foo/></mydoc>
<- >
<- > I could model the corresponding tree with ASCII art like this:
<- >
<- >    element 'mydoc'
<- >       |___element 'foo'
<- >       |___element 'greeting'
<- >       |     |  \___attribute 'xml:lang' w/value 'en'
<- >       |     |___text 'hello'
<- >       |___element 'foo'
<- >
<- > Whitespace can be significant, so the above is not necessarily
<- the same as
<- >
<- > <mydoc>
<- >    <foo></foo>
<- >    <greeting xml:lang="en">hello</greeting>
<- >    <foo/>
<- > </mydoc>
<- >
<- > although I'm sure you'll agree it is much easier to read when text is
<- > inserted between the tags like that.
<- >
<- > As I said, this is just a simplistic introduction to get you
<- started and
<- to
<- > demonstrate the hierarchical nature of XML. There's a lot more to know.
<- Get
<- > a good book on the subject.
<-