[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmlbeans-user
Subject:    RE: Using cursor to ierate and adding to map
From:       "Cezar Andrei" <cezar () bea ! com>
Date:       2007-12-12 20:19:38
Message-ID: BF6B6CA032BA0A429BD924F96765147D73D49C () repbex02 ! amer ! bea ! com
[Download RAW message or body]

Zapo,

cursor.getName() returns the name of the current token. You need to make
sure you move the cursor on the right element to get the text and move
back to the parent "Testcase" and call toNextSibling().

> -----Original Message-----
> From: Zapo [mailto:arun_9033@yahoo.com]
> Sent: Tuesday, December 11, 2007 5:17 PM
> To: user@xmlbeans.apache.org
> Subject: Using cursor to ierate and adding to map
> 
> 
> Greetings,
> 
> I am trying to iterate a XML using cursor and then adding to MAP.
> The XML has repetable nodes for example
> 
> <Testcase>
> <Security>https</Security>
> <Server>staging</Server>
> </Testcase>
> <Testcase>
> <Security>https</Security>
> <Server>baijing</Server>
> </Testcase>
> </Testcases>
> 
> I have an array of TestCase objects ready, how to iterate and add to a
Map
> or Array
> 
> I tried the following way and it did not get too further..I seem to be
> missing the usage of cursor and addin to a MAP, I seem to overwrite my
MAP
> (which I should avoid),
> 
> 		private static void addtoMap(Testcase item2, int i,
> 			LinkedHashMap<String, String> linkedHashMap) {
> 
> 			XmlCursor cursor = item.newCursor();
> //Iterate throught the nodes
> 
> 			cursor.toChild(0);
> 			String name = cursor.getName().toString();
> 			String value = cursor.getTextValue();
> 
> 			//Add to Map
> 			linkedHashMap.put(name, value);
> 
> 			//Next Sibling
> cursor.toNextSibling();
> 
> 			String name1 = cursor.getName().toString();
> 			String value1 = cursor.getTextValue();
> 
> //Add to Map again
> 			linkedHashMap.put(name, value);
> 
> 
> 			System.out.println("Type of Token is: " +
> 			    cursor.currentTokenType() +
> 			  "\nText of Token is" + cursor.xmlText());
> 			//}
> 			cursor.dispose();
> 
> 	}
> 
> 
> 
> 
> 
> 
> --
> View this message in context: http://www.nabble.com/Using-cursor-to-
> ierate-and-adding-to-map-tp14285663p14285663.html
> Sent from the Xml Beans - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org


Notice:  This email message, together with any attachments, may contain information  \
of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be \
confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended \
solely for the use of the individual or entity named in this message. If you are not \
the intended recipient, and have received this message in error, please immediately \
return this by email and then delete it.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic