Forum Stats

  • 3,853,528 Users
  • 2,264,231 Discussions
  • 7,905,381 Comments

Discussions

XML to delimited text

Celvin Kattookaran
Celvin Kattookaran Member Posts: 3,143 Gold Trophy
edited Aug 11, 2013 4:38AM in New To Java

Hi I'm a newbie to Java and would like to know whether this can be achieved.

<Membername="West"

HierarchyType="Disabled"

>

<Membername="California"

>

<AttributeMemberdimension="Population"

name="33000000"

/>

<UDA >Major Market</UDA>

</Member>

</Member>

I tried getting it as a | delimited text and wrote this code

NodeList AppList = doc.getElementsByTagName("Member") ;
  for(int i= 0; i <AppList.getLength() ; i ++)
  {
  Element MbrElement = (Element) AppList.item(i);

    NodeList UDAElmntLst = MbrElement.getElementsByTagName("UDA");
    
  for(int i1= 0; i1 <UDAElmntLst.getLength() ; i1 ++)
  {
    Element UDANmElmnt = (Element) UDAElmntLst.item(i1);
    System.out.println(MbrElement.getAttribute("name") + "|"+UDANmElmnt.getTextContent());
  }
  }

What i expect is this

California|Major Market

and what i get is

West|New Market

California|Major Market

Why is it giving me West? West doesn't have a UDA tag

Tagged:

Answers

This discussion has been closed.