Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 27th, 2004, 07:07 AM
Registered User
 
Join Date: Feb 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to tutul128
Default Geting Index of a children

Dear friends
 I am in big problem with geting index of a children. I am using JDOM parser. My XML document's format is like as follows----

<names>
  <name>
     <first>Hassanur</first>
     <last>Rahman</last>
  </name>
  <name>
     <first>Mofizur</first>
     <last>Rabbani</last>
  </name>
</names>


I can't get the index of 'name' children. I need this index to insert and delete operation in JDOM parser. Somebody please help me
                                              Tutul




Hassanur
 
Old May 27th, 2004, 09:00 AM
Authorized User
 
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

Hassanur,

one thing you have to bear in mind is that when inserting/deleting in any DOM parser, the index values will change, so if you're doing this in a FOR loop, and you do an insert and on the next iteration you delete, you're pretty much not doing anything, not to mention if you do a delete, you'll get an out of bounds error when trying to reference what you thought was your last node.

that said, I don't know the specifics about JDOM, but if you do:

documentElement.selectNodes ("names/name")

you'll get a reference to all the names node, now if you do

myNodes = documentElement.selectNodes ("names/name[first='Hassanur']")

you'll get a reference to all the name nodes whos first text = 'Hassanur'
then you get the first one by doing myNodes.item(0)

Hope this helps, though I'm not sure if it answers your question


thanks
 
Old May 27th, 2004, 10:34 AM
Registered User
 
Join Date: Feb 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to tutul128
Default

if I add an attribute in name node like <name id="1"> or a chile node under every name node like "<id>1</id>" and this id will work as a primary key then how can I get the corresponding name node's index in JDOM parser. This is my original problem and for your kind information I am weak in Java coading.

Hassanur





Similar Threads
Thread Thread Starter Forum Replies Last Post
geting the value from an Object JAdkins Classic ASP Basics 1 June 29th, 2007 10:59 AM
Problem in geting the @@Identity Value janamca_thanan Biztalk 0 December 17th, 2006 09:31 AM
geting money type from sql msrnivas Classic ASP Components 1 July 19th, 2004 11:09 AM
geting money type from sql msrnivas .NET Web Services 1 July 19th, 2004 06:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.