[jdom-interest] JDOM Parsing Problems

Hunter Hillegas timebomb at west.net
Sat Dec 8 14:27:28 PST 2001


I am having trouble parsing an XML document with JDOM and I'm not sure what
is going wrong.

Here is my code:

try {              
//parse XML response using JDOM
InputStream in = urlCon.getInputStream();
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(in);
                
System.out.println("JDOM Has: " + doc.toString()); //DEBUG
                
Element docRoot = doc.getRootElement(); //get the root
quotedPrice = 
docRoot.getChild("IntlRateResponse").getChild("Package").getChild("Service")
.getChild("Postage").getText();
}
catch (Exception e) {
System.out.println("ShippingManager: Error parsing USPS response...");
System.out.println("USPS Response: " + quotedPrice); //DEBUG
throw new EJBException(e.toString());
}

This is throwing the exception... I know that the InputStream contains valid
XML and it looks like JDOM is getting the document as I get this on the
console:

14:20:04,200 INFO  [Default] JDOM Has: [Document:  No DOCTYPE declaration,
Root is [Element: <IntlRateResponse/>]]
14:20:04,205 INFO  [Default] ShippingManager: Error parsing USPS response...

Here is the XML that I am trying to parse. I'm not sure that I am using the
correct child element names but I've tried several combinations and they
don't work... I do have almost identical code with different incoming XML
that works correctly, so it has something to do with this document... Any
ideas?

Thanks,
Hunter


<?xml version="1.0"?>
<IntlRateResponse><Package ID="0"><Prohibitions>Articles bearing false
trademarks or lacking the indication of origin required by the Irish
regulations.  
Coins minted in a foreign country, except gold and silver; false or
counterfeit coins. 
Hay, straw, including articles made of straw.
Peat moss litter except under license.
Prison-made goods. 
Safety fuses; fireworks.
Tobacco, cigars or cigarettes packed with other articles. Cut and
compressed, sweetened, or adulterated
tobacco.</Prohibitions><Restrictions>Carbon paper, except for typewriter
carbon paper that must be described on the customs declaration as follows:
Typewriter carbon paper coated with wax and containing no oxidizable or
fatty substances." 
Circulars or advertisements relating to the prevention or treatment of
venereal disease must be addressed to physicians or pharmacists.
Import licensing information is contained in the Irish Customs and Excise
Tariff, which may be obtained from the Secretary, Revenue Commissioners,
Dublin Castle, Dublin 2 and from the Government Publications Sales Office,
GPO Arcade, Dublin 1.
Importation of tea is subject to certain customs regulations.
Many other goods, including certain fruit, vegetables and other foodstuffs,
plants and seeds, and certain pharmaceutical products are subject to special
regulations.  
Margarine, skimmed milk, and other diluted or adulterated foodstuffs must be
suitably labeled.  
Oiled or varnished cloth or similar articles must be accompanied by a
certificate as follows:  The oilcloth or similar articles in this parcel
have been stored at a temperature of 140_F until completely dried, and then
cured for at least a month before packing."  Only in parcel post.
The following goods are subject to quota restrictions and require an import
license:  boots and shoes, brushes, electric lamp bulbs, screws, tapered
thread; felt hats and caps for women and girls; brushes and mops; wheaten
flour and any commodity or product of wheat; rubber proofed wearing apparel;
sparking plugs and component parts; silk and artificial silk hose; and
certain woven fabrics.</Restrictions><Observations>1. The names of the
counties in Ireland are as follows:  Carlow, Cavan, Clare, Cork, Donegal,
Dublin, Galway, Kerry, Kildare, Kilkenny, Leitrim, Laioghis, Limerick,
Longford, Louth, Mayo, Meath, Monaghan, Offaly, Roscommon, Sligo, Tipperary,
Waterford, Westmeath, Wexford, and Wicklow.
2. The names of the county and the delivery office must form a part of the
address of all mail articles.
3. In the case of articles liable to customs duty that are eligible for
preference, the preferential tariff will not be applied unless the customs
declaration is inscribed in bold characters:  Preference claimed -
Certificate of origin enclosed." Otherwise, the full customs duties will be
applied to the articles.
4. The same applies to goods imported under permit, unless the declaration
is clearly marked Imported under license," and unless the relative license
is produced at the time of customs examination. In such cases the license
should be produced before the goods are
imported.</Observations><CustomsForms>Postal Union Mail (LC/AO): PS Form
2976 or 2976-A (see 123.61)
Parcel Post: PS Form 2976-A inside 2976-E
(envelope)</CustomsForms><ExpressMail>Country Code
IE  

Reciprocal Service Name
Express Mail  

Required Customs Form/Endorsement
1. For business papers and documents only:
No form required. Endorse item clearly next to mailing label as BUSINESS
PAPERS. 

2. For merchandise samples without commercial value:
PS Form 2976, Customs - CN 22 (Old C 1) and Sender's Declaration (green
label). 

3. For merchandise and all articles subject to customs duty:
PS Form 2976-A, Customs Declaration and Dispatch Note CP 72, inside a PS
Form 2976-E, Customs Declaration Envelope CP 91. A commercial invoice must
be enclosed in each item.

Note:
1. All items must have both the county and city in the address.
2. Coins; banknotes; currency notes (paper money); securities of any kind
payable to bearer; traveler's checks; platinum, gold, and silver
(manufactured or not); precious stones; jewelry; and other valuable articles
are prohibited in Express Mail International Service shipments to Ireland.

Areas Served:

All</ExpressMail><AreasServed>All</AreasServed><Service
ID="0"><Pounds>1</Pounds><Ounces>0</Ounces><MailType>Package</MailType><Coun
try>IRELAND</Country><Postage>39</Postage><SvcCommitments>See Service
Guide</SvcCommitments><SvcDescription>Global Express Guaranteed Document
Service</SvcDescription><MaxDimensions>Max. length 46", width 35", height
46" and max. length plus girth
108"</MaxDimensions><MaxWeight>70</MaxWeight></Service><Service
ID="1"><Pounds>1</Pounds><Ounces>0</Ounces><MailType>Package</MailType><Coun
try>IRELAND</Country><Postage>44</Postage><SvcCommitments>See Service
Guide</SvcCommitments><SvcDescription>Global Express Guaranteed Non-Document
Service</SvcDescription><MaxDimensions>Max. length 46", width 35", height
46" and max. length plus girth
108"</MaxDimensions><MaxWeight>70</MaxWeight></Service><Service
ID="2"><Pounds>1</Pounds><Ounces>0</Ounces><MailType>Package</MailType><Coun
try>IRELAND</Country><Postage>19.15</Postage><SvcCommitments>2 - 3
Days</SvcCommitments><SvcDescription>Global Express Mail
(EMS)</SvcDescription><MaxDimensions>Max. length 36", max. length plus girth
79"</MaxDimensions><MaxWeight>44</MaxWeight></Service><Service
ID="3"><Pounds>1</Pounds><Ounces>0</Ounces><MailType>Package</MailType><Coun
try>IRELAND</Country><Postage>9</Postage><SvcCommitments>3 - 5
Days</SvcCommitments><SvcDescription>Global Priority Mail - Flat-rate
Envelope (large)</SvcDescription><MaxDimensions>9-1/2" x
12-1/2"</MaxDimensions><MaxWeight>4</MaxWeight></Service><Service
ID="4"><Pounds>1</Pounds><Ounces>0</Ounces><MailType>Package</MailType><Coun
try>IRELAND</Country><Postage>5</Postage><SvcCommitments>3 - 5
Days</SvcCommitments><SvcDescription>Global Priority Mail - Flat-rate
Envelope (small)</SvcDescription><MaxDimensions>6" x
10"</MaxDimensions><MaxWeight>4</MaxWeight></Service><Service
ID="5"><Pounds>1</Pounds><Ounces>0</Ounces><MailType>Package</MailType><Coun
try>IRELAND</Country><Postage>10</Postage><SvcCommitments>3 - 5
Days</SvcCommitments><SvcDescription>Global Priority Mail - Variable Weight
Envelope (single)</SvcDescription><MaxDimensions>Max. length 24", Max.
length, height, depth combined
36"</MaxDimensions><MaxWeight>4</MaxWeight></Service><Service
ID="6"><Pounds>1</Pounds><Ounces>0</Ounces><MailType>Package</MailType><Coun
try>IRELAND</Country><Postage>8.7</Postage><SvcCommitments>4 - 7
Days</SvcCommitments><SvcDescription>Airmail Letter
Post</SvcDescription><MaxDimensions>Max. length 24", Max. length, height,
depth combined 36"</MaxDimensions><MaxWeight>4</MaxWeight></Service><Service
ID="7"><Pounds>1</Pounds><Ounces>0</Ounces><MailType>Package</MailType><Coun
try>IRELAND</Country><Postage>14</Postage><SvcCommitments>4 - 7
Days</SvcCommitments><SvcDescription>Airmail Parcel
Post</SvcDescription><MaxDimensions>Max.length 60", max. length plus girth
108"</MaxDimensions><MaxWeight>66</MaxWeight></Service><Service
ID="8"><Pounds>1</Pounds><Ounces>0</Ounces><MailType>Package</MailType><Coun
try>IRELAND</Country><Postage>3.8</Postage><SvcCommitments>4 - 6
Weeks</SvcCommitments><SvcDescription>Economy (Surface) Letter
Post</SvcDescription><MaxDimensions>Max. length 24", Max. length, height,
depth combined 36"</MaxDimensions><MaxWeight>4</MaxWeight></Service><Service
ID="9"><Pounds>1</Pounds><Ounces>0</Ounces><MailType>Package</MailType><Coun
try>IRELAND</Country><Postage>18.25</Postage><SvcCommitments>4 - 6
Weeks</SvcCommitments><SvcDescription>Economy (Surface) Parcel
Post</SvcDescription><MaxDimensions>Max.length 60", max. length plus girth
108"</MaxDimensions><MaxWeight>66</MaxWeight></Service></Package></IntlRateR
esponse>




More information about the jdom-interest mailing list