[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: how to save an n-ary tree of nodes to and from an x ml fil

  • To: xml-dev@l...
  • Subject: RE: how to save an n-ary tree of nodes to and from an x ml file?
  • From: Doug Rudder <drudder@d...>
  • Date: Mon, 12 Sep 2005 15:37:16 -0500

ary subscription
The error is caused by an extra / in the open <data> tag (<data/>0</data>
should be <data>0</data>).

-----Original Message-----
From: Anil Philip [mailto:goodnewsforyou@y...] 
Sent: Monday, September 12, 2005 3:27 PM
To: xml-dev@l...
Subject: RE:  how to save an n-ary tree of nodes to and from an x
ml file?

Thank you - that went thru XMLSpy - dont know why the earlier one was wrong.

I tried to generate the instance file for a node (0) with 3 children (1,2,3)
but xmlspy complains that "Node closing element name expected". Thanks again
for your help.

<?xml version="1.0" encoding="UTF-8"?>
<Node
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\Projects\ACD\acd_schema3.xsd">
	<childNodes><Node>
		<childNodes></childNodes>
		<data>1</data>
	</Node><Node>
		<childNodes></childNodes>
		<data>2</data>
	</Node><Node>
		<childNodes></childNodes>
		<data>3</data>
	</Node></childNodes>
	<data/>0</data>
</Node>





--- Doug Rudder <drudder@d...> wrote:

> Anil -
> 
> Your ListOfNodes element should be a complexType (as referenced by 
> childNodes). Something like this might work:
> 
> <?xml version="1.0" encoding="UTF-8"?> <xs:schema 
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>    elementFormDefault="qualified"
>    attributeFormDefault="unqualified">
> 
>    <xs:complexType name="ListOfNodes">
>       <xs:sequence>
>          <xs:element ref="Node" minOccurs="0"
>             maxOccurs="unbounded"/>
>       </xs:sequence>
>    </xs:complexType>
> 
>    <xs:element name="Node">
>       <xs:annotation>
>          <xs:documentation>ACD nodes - 2. Copyright juwo LLC 
> 2005</xs:documentation>
>       </xs:annotation>
>       <xs:complexType>
>          <xs:sequence>
>             <xs:element name="childNodes"
> type="ListOfNodes"/>
>             <xs:element name="data"
> type="xs:string"/>
>          </xs:sequence>
>       </xs:complexType>
>    </xs:element>
> </xs:schema>
> 
> Doug
> 
> -----Original Message-----
> From: Anil Philip [mailto:goodnewsforyou@y...]
> Sent: Monday, September 12, 2005 2:50 PM
> To: xml-dev@l...
> Subject: RE:  how to save an n-ary tree of nodes to and from 
> an xml file?
> 
> Michael, Thanks for your reply.
> Yes, I removed the parent link. However I think the schema is not 
> correct - XML Spy complains but I cant see whats wrong:
> ---
> <?xml version="1.0" encoding="UTF-8"?> <xs:schema 
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified">
> 	<xs:element name="Node">
> 		<xs:annotation>
> 			<xs:documentation>ACD nodes - 2. Copyright juwo LLC 
> 2005</xs:documentation>
> 		</xs:annotation>
> 		<xs:complexType>
> 			<xs:sequence>
> 				<xs:element name="childNodes"
> type="ListOfNodes"/>
> 				<xs:element name="data" type="xs:string"/>
> 			</xs:sequence>
> 		</xs:complexType>
> 		<xs:element name="ListOfNodes">
> 			<xs:complexType>
> 				<xs:sequence>
> 					<xs:element ref="Node" minOccurs="0"
> maxOccurs="unbounded"/>
> 				</xs:sequence>
> 			</xs:complexType>
> 		</xs:element>
> 	</xs:element>
> </xs:schema>
> 
> --- Michael Kay <mike@s...> wrote:
> 
> > > I am trying to find how to implement something
> in
> > XML
> > > and was disappointed and surprised to find not
> too many in-depth
> > > tutorials or information; unlike in
> > Java
> > > where the Sun Java tutorial at java.sun.com is
> > enough
> > > to get one working productively...
> > > [ok, rant over]
> > > 
> > > ---
> > > I am trying to represent a n-ary tree of nodes
> in
> > xml.
> > > More accurately, I am trying to save/instantiate
> a tree of nodes
> > > to-from an xml file.
> > > Am finding it difficult trying to represent the
> parent-child
> > > relationships.
> > > 
> > > Java: (simplified)
> > > -----
> > > 
> > > class Node {
> > > Arraylist childNodes;
> > > Node parent;
> > > String data;
> > > }
> > 
> > The "parent" pointer here is redundant (you could
> reconstruct it from
> > other information). In my experience, when
> designing XML data
> > structures it's best to avoid such redundancy. All
> it achieves is to
> > increase the burden on senders to make the
> document consistent and on
> > recipients to check that it is indeed consistent.
> > 
> > Once you eliminate the redundancy, you seem to
> have a pure hierarchy,
> > with a very natural XML representation:
> > 
> > <node>
> >   <node>
> >     <data>x</data>
> >   </node>
> >   <node/>
> >   <node>
> >     <node/>
> >     <node>
> >       <data>x</data>
> >       <node/>
> >       <node/>
> >     </node>
> >   </node>
> > </node>
> > 
> > Of course, you could flatten this if you prefer so
> all the nodes are
> > on the same level, and the hierarchic relationship
> are represented by
> > id/idref attributes. But it seems more natural to
> use the XML
> > hierarchy to represent the information hierarchy
> when you can.
> > 
> > Michael Kay
> > http://www.saxonica.com/
> > 
> > 
> > 
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com
> 
>
-----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org
> <http://www.xml.org>, an initiative
> of OASIS <http://www.oasis-open.org>
> 
> The list archives are at
> http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the
> subscription
> manager:
> <http://www.oasis-open.org/mlmanage/index.php>
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this list use the subscription
manager: <http://www.oasis-open.org/mlmanage/index.php>

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.