[XOM-interest] Simple Data Iteration...

dirk bergstrom dirk at juniper.net
Wed Dec 17 17:45:14 EST 2003


Nils_Kilden-Pedersen at Countrywide.Com expounded at length upon:
> Document doc = Builder.build(file);
> Element root = doc.getRootElement();
> Element parameters = root.getFirstChildElement("PARAMETERS");
> Elements elementList = parameters.getChildElements("PARAMETER");
> for (int i = 0; i < elementList.size(); i++) {
>         Element parameter = elementList.get(i);

          // adding the missing bits...
          Element pn = parameter.getFirstChildElement("PARAM_NAME");
	  String pnval = pn.getValue();
          Element ps = parameter.getFirstChildElement("PARAM_SIZE");
	  String psval = ps.getValue();
          if (<regex match against pnval>) {
                  // That's one you want
>         } else if ( "10".equals(psval)) {
>                 // That's one you want
>         }
> }

The above is subject to a host of NullPointerExceptions.  You are
encouraged to validate against an xml schema (or DTD, if you're brave), or
insert a lot of checks for nulls.  If you're really paranoid, do both.

> adotson at ci.portland.or.us wrote on 12/17/2003 02:16:15 PM:
> 
>> I feel very feeble, since from what I have read, this is a very easy 
> package
>> to use.
>> First, I haven't been able to search the archives, all words entered 
> return
>> no results, so if this is a very basic question that is in the archive I
>> apologize, I tried to scan the past subject lines of threads to see if 
> it
>> had been asked.
>> 
>> I have a very simple document:
>> <PARAMETERS>
>> <PARAMETER>
>>   <PARAM_NAME>longer param</PARAM_NAME>
>>   <PARAM_SIZE>20</PARAM_SIZE>
>> </PARAMETER>
>> <PARAMETER>
>>   <PARAM_NAME>shorter param</PARAM_NAME>
>>   <PARAM_SIZE>10</PARAM_SIZE>
>> </PARAMETER>
>> <PARAMETER>
>>   <PARAM_NAME>another shorter param</PARAM_NAME>
>>   <PARAM_SIZE>10</PARAM_SIZE>
>> </PARAMETER>
>> </PARAMETERS>
>> 
>> I'd like to find all elements with a param_size of 10 in the order they 
> are
>> found in the doc. Or, all param_name(s) that match "shorter param".
>> 
>> Just looking for some hints or a direction...
>> 
>> Thanks, Anthony
>> _______________________________________________
>> XOM-interest mailing list
>> XOM-interest at lists.ibiblio.org
>> http://lists.ibiblio.org/mailman/listinfo/xom-interest
>> 
> _______________________________________________
> XOM-interest mailing list
> XOM-interest at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/xom-interest


-- 
Dirk Bergstrom               dirk at juniper.net
_____________________________________________
Juniper Networks Inc.,          Computer Geek
Tel: 408.745.3182           Fax: 408.745.8905




More information about the XOM-interest mailing list