[jdom-interest] [Newbie] - Problem using Entity

Jakob Breivik Grimstveit jakobbg at reaktor.no
Tue May 8 16:11:43 PDT 2001


I'm trying from a java program to output a data structure to XML, so other
applications can use this information as smoothly as possible. I am a newbie,
so I might use the JDOM API totally wrong, but I take a chance on asking you
nevertheless:

When adding entities, I assume they are supposed to be added to Elements with
addContent(Entity). Code runs smoothly, but when printing to file, all
entities within an Element is displayed somewhat un-well-formed :-). Look
below:

<Folder id="0">
 <Folder id="185">
&Name;  <Folder id="195">
&Name;   <Item price="0.0">
    <Description />
    <UserDefined>
&Comment;&Title;&Bitrate;&Year;    </UserDefined>
   </Item>
   <Item price="0.0">
    <Description />
    <UserDefined>
&Comment;&Title;&Bitrate;&Year;    </UserDefined>
   </Item>
  </Folder>
 </Folder>
</Folder>

As you can see here, I'm adding MP3 file info to an XML file, but all entity
info is printed as above. Lets add some code which I'm using as well:

    /* Add new subelement to currentElement and give it an ID attribute and
name, as all other Elements */
    Element subElement=new Element("Folder");
    Entity tmpEntity = new Entity("Name").setContent(tmpNode.getName());
    subElement.addContent(tmpEntity);
    subElement.addAttribute("id", Integer.toString(tmpNode.getNodeNumber()));
    currentElement.addContent(subElement);

and

   while(keysEnum.hasMoreElements()) {
    Object key=keysEnum.nextElement();
    Entity userDefinedEntity=new Entity(key.toString());
    userDefinedEntity.setContent(thisUserDefined.getValue(key).toString());
    userDefinedElement.addContent(userDefinedEntity);
   }

As you can see - every time I try to output my Element data structure, it
goofs up like this. What do I do wrong? Are there any good examples out there?
I am using XMLoutputter.


- yours sincerely...
- Jakob Breivik Grimstveit, jakob at grimstveit.net, www.grimstveit.net
- Morvikbotn 341, 5121 Ulset, Norway, tlf: 55195667, mob: 98833857




More information about the jdom-interest mailing list