RE: [xmljs-users] Re-ordering XML data...
Brought to you by:
djoham,
witchhunter
|
From: Eljon G. <eg...@re...> - 2005-02-04 23:44:20
|
In the example below, the function would be moveSectionUp() or moveSectionD=
own(). Those functions call updateNode(), which is I function I wrote to f=
ind the node and use tNode.getFirstChild().setNodeValue(tValue), which actu=
ally resets the order of the section. I think your idea of re-ordering the=
nodelist is something I had not considered but should be possible once I t=
hink it out....Thanks for the inspiration...
So far i have come up with....This function would be called right before I =
save the XML object to the hidden form field.
function reOrderNodes(){
// Re-order the nodes so that the XML document accurately reflects the cha=
nges made
var tSections =3D pageRoot.getElementsByTagName(sectionElement); // secti=
onElement =3D 'section'
var tTempObj =3D null; // used to temporary swap nodes
var i =3D 0;
=20
// First do sections
tCurrentSection =3D pageRoot.getElementsByTagName(sectionElement).item(i)=
;
tCurrentSectionOrder =3D tCurrentSection.getElementsByTagName(orderElemen=
t).item(i); // orderElement =3D 'orderNumber'
=20
while(tCurrentSection.getNextSibling() !=3D null) {
=20
tNextSection =3D pageRoot.getElementsByTagName(sectionElement).item(i+1)=
;
tNextSectionOrder =3D tNextSection.getElementsByTagName(orderElement).it=
em(0);
=20
// if current section order is greater than next section swap
if(tCurrentSectionOrder.getFirstChild().getNodeValue() > tNextSectionOrd=
er.getFirstChild().getNodeValue()) {
tTempObj =3D tCurrentSection;
tCurrentSection =3D tNextSection;
tNextSection =3D tTempObj;
} else {
break;
}
=20
tCurrentSection =3D pageRoot.getElementsByTagName(sectionElement).item(i=
);
i++;
}
}=20
Let me know if I am now in the right direction...Thanks...
P.S. I had plans to work alittle this weekend on this but I might not...Su=
per Bowl is in town...Party on!!!!!!!!!!!!!
Eljon Greene
CE Software Engineer
877.394.5644 \\ main
904.567.2127 \\ direct
eg...@re...
www.recruitmax.com
From: David Joham
Sent: Fri 2/4/2005 5:53 PM
To: Eljon Greene; xml...@li...
Subject: Re: [xmljs-users] Re-ordering XML data...
Can you do a quick example (just the XML below and how you're trying to man=
ipulate it) so I can
take a look this weekend? I know the XPATH stuff in xmljs is pretty basic a=
nd probably doesn't
support what you're looking for, but it may be possible to enhance it to su=
pport what you're
looking for. At the very least, it should be easy to create a function that=
will reorder a
nodelist in whatever way you're looking for...
David
--- Eljon Greene <eg...@re...> wrote:
> Hi,
>=20
> This is my last hurdle to overcome (I think) in using XML and the xmlJS l=
ibrary. I use this
> technology to allow users to control the layout (order, active/inactive, =
labeling) of pages in
> our application. However the ordering is based on an <orderNumber> eleme=
nt I created by it does
> not change the "position" of the <section> in the XML file. My question =
is there a way to
> re-order elements? I can only display the elements by using the XPath po=
sition() function.=20
> Here is the way it works now and the desired result:
>=20
> How it looks now:
>=20
>=20
> <section>
> <id>1</id>
> <name>My Section</name>
> <orderNumber>02</orderNumber>
> <active>Yes</active>
> <locked>Yes</locked>
> </section>
> <section>
> <id>2</id>
> <name>My Other Section</name>
> <orderNumber>01</orderNumber>
> <active>Yes</active>
> <locked>Yes</locked>
> </section>
> The desired results:
>=20
> <section>
> <id>2</id>
> <name>My Other Section</name>
> <orderNumber>01</orderNumber>
> <active>Yes</active>
> <locked>Yes</locked>
> </section>
> <section>
> <id>1</id>
> <name>My Section</name>
> <orderNumber>02</orderNumber>
> <active>Yes</active>
> <locked>Yes</locked>
> </section>
>=20
> Thanks.
>=20
> Eljon Greene
> CE Software Engineer
> 877.394.5644 \\ main
> 904.567.2127 \\ direct
> eg...@re...
> www.recruitmax.com
>=20
|