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

Brett McLaughlin brett at newInstance.com
Tue Mar 27 10:49:16 PST 2001


----- Original Message -----
From: "Alex Colic" <alex.colic at pop-ware.com>
To: "JDOM" <jdom-interest at jdom.org>
Sent: Tuesday, March 27, 2001 5:43 PM
Subject: [jdom-interest] Attribute not being set to true?


>
> 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>

Once you get the desired Property element, simply use
addAttribute("Required", "false");

You should really read the JavaDoc and related articles posted on the site
;-)

-Brett

>
> Thanks for any help.
>
> Regards
>
>
> Alex Colic
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com




More information about the jdom-interest mailing list