Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Simple Data Iteration...

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: dirk bergstrom <dirk AT juniper.net>
  • To: adotson AT ci.portland.or.us
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] Simple Data Iteration...
  • Date: Wed, 17 Dec 2003 14:45:14 -0800

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





Archive powered by MHonArc 2.6.24.

Top of Page