RE: [xmljs-users] Re-ordering XML data...
Brought to you by:
djoham,
witchhunter
From: David J. <dj...@ya...> - 2005-02-05 21:43:45
|
From what I gather you're trying to do, it looks like your going in the right direction... Good luck! David --- Eljon Greene <eg...@re...> wrote: > In the example below, the function would be moveSectionUp() or moveSectionDown(). Those > functions call updateNode(), which is I function I wrote to find the node and use > tNode.getFirstChild().setNodeValue(tValue), which actually 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 think 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 changes made > var tSections = pageRoot.getElementsByTagName(sectionElement); // sectionElement = 'section' > var tTempObj = null; // used to temporary swap nodes > var i = 0; > > // First do sections > tCurrentSection = pageRoot.getElementsByTagName(sectionElement).item(i); > tCurrentSectionOrder = tCurrentSection.getElementsByTagName(orderElement).item(i); // > orderElement = 'orderNumber' > > while(tCurrentSection.getNextSibling() != null) { > > tNextSection = pageRoot.getElementsByTagName(sectionElement).item(i+1); > tNextSectionOrder = tNextSection.getElementsByTagName(orderElement).item(0); > > // if current section order is greater than next section swap > if(tCurrentSectionOrder.getFirstChild().getNodeValue() > > tNextSectionOrder.getFirstChild().getNodeValue()) { > tTempObj = tCurrentSection; > tCurrentSection = tNextSection; > tNextSection = tTempObj; > } else { > break; > } > > tCurrentSection = pageRoot.getElementsByTagName(sectionElement).item(i); > i++; > } > } > > 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...Super 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 manipulate it) so I can > take a look this weekend? I know the XPATH stuff in xmljs is pretty basic and probably doesn't > support what you're looking for, but it may be possible to enhance it to support 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, > > > > This is my last hurdle to overcome (I think) in using XML and the xmlJS library. 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> element 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 position() function. > > Here is the way it works now and the desired result: > > > > How it looks now: > > > > > > <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: > > > > <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> > > > > Thanks. > > > > Eljon Greene > > CE Software Engineer > > 877.394.5644 \\ main > > 904.567.2127 \\ direct > > eg...@re... > > www.recruitmax.com > > > |