[jdom-interest] getChildren

Travis, Mark MTravis at skm.com.au
Wed Dec 18 17:01:55 PST 2002


I would use XSL for this. The folloing script 

	<?xml version="1.0" encoding="UTF-8"?>
	<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
	
		<xsl:template match="*">
			<xsl:copy-of select="." />
		</xsl:template>

		<xsl:template match="/instance">
			<instance>
				<xsl:apply-templates>
					<xsl:sort order="descending"
select="name()"/>
				</xsl:apply-templates>
			</instance>
		</xsl:template>
	</xsl:stylesheet>

converts

	<?xml version="1.0" encoding="UTF-8"?>
	<?xml-stylesheet type="text/xsl" href="D:\jdom\Example
2\watcher.xslt"?>
	<instance>
		<watcher>a</watcher>
		<watcher>b</watcher>
		<tupleID>1</tupleID>
		<tupleID>3</tupleID>
		<watcher>c</watcher>
	</instance>

into

	<?xml version="1.0" encoding="UTF-8"?>
	<instance>
		<watcher>c</watcher>
		<watcher>b</watcher>
		<watcher>a</watcher>
		<tupleID>3</tupleID>
		<tupleID>1</tupleID>
	</instance>

I hope this helps

Mark

-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]
On Behalf Of ted.erickson at usbank.com
Sent: Saturday, 14 December 2002 1:41 AM
To: jdom-interest at jdom.org
Subject: Re: [jdom-interest] getChildren


Hopefully someone has a better answer to this problem.

The problem:

Grab all children named "watcher" from a list
Append a new child to the list of watchers

The new child appears at the end of the original list instead of at the
end of the watchers list

The solution:

 1- get the list of "tupleID"
 2- remove the children named "tupleID"
 3- add the new "watcher" node
 4- walk through the list of "tupleID" and add each node to the list

Does anyone have a more elegant or intuitive solution?

Ted Erickson

-------------------------
Yes, but i would that the new added watcher will be at the end of the
list of the watcher and not at the end of the element tupleID, because i
have a sequence in the xsd schema associated and so the order must be
respect!!!! How can relize it?

<instance>
             <watcher>a</watcher>
             <watcher>b</watcher>
                         <watcher>c</watcher>
             <tupleID>1</tupleID>
             <tupleID>3</tupleID>

</instance>

MANY THANKS

------------------------------------------------------------------------
---------------------------------
Yanked incorrect reply ...
------------------------------------------------------------------------
---------------------------------

i have an element accesslist with inside a sequence of instance
element.Each instance consist on 2 different element named watcher and
tupleid. <instance>
             <watcher>a</watcher>
             <watcher>b</watcher>
             <tupleID>1</tupleID>
             <tupleID>3</tupleID>
</instance>

My desire is to add a new element watcher. So i do:

List watchers = instance.getChildren("watcher");

Element newatcher = new Element("watcher"); newatcher.setText("c");
watchers.add(newatcher);

but i get:

<instance>
             <watcher>a</watcher>
             <watcher>b</watcher>
             <tupleID>1</tupleID>
             <tupleID>3</tupleID>
             <watcher>c</watcher>
</instance>

that it's wrong!!!Where i do the mistake?
BRGS
Antonello



_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@you
rhost.com




More information about the jdom-interest mailing list