[jdom-interest] Attribute not being set to true?

Alex Colic alex.colic at pop-ware.com
Tue Mar 27 15:43:08 PST 2001


Hi, I have figured out how to set attributes. At least I think I have.

If my xml file is as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<WorkRequest>
  <Property Required="false">Entity</Property>
  <Property Required="false">Priority</Property>
  <Property Required="false">Work Type</Property>

then the following should set the Property with a text value of Priority to
true:

  List properties=doc.getRootElement().getChildren("Property");
  Iterator iter=properties.iterator();
  List newValues=new Vector();

  while(iter.hasNext())
  {
    childElement=(Element)iter.next();
    strPropertyName=childElement.getTextTrim();
    if(strPropertyName.equal("Priority"))
      {
        newValues.add(new Attribute("Required","true"));
        childElement.setAttributes(newValues);
        newValues.clear();
      }
  }

I then save the new file via:

  XMLOutputter out=new XMLOutputter();
  Document doc=util.getXMLDocument();
  try
  {
    out.output(doc,new BufferedOutputStream(new FileOutputStream(f)));
  }
  catch(Exception e){}

The problem is my resulting xml file is as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<WorkRequest>
  <Property Required="false">Entity</Property>
  <Property>Priority</Property>
  <Property Required="false">Work Type</Property>

The required parameter is missing.

Any idea how to get the required parameter to equal:
<Property Required="true">Priority</Property>

Thanks for any help.

Regards


Alex Colic




More information about the jdom-interest mailing list