How do I check for empty tags while parsing xml?

surfer-08

New Member
I am using the Document object to extract all the tags from an xml. If the xml has an empty tag, I get a null pointer exception. How do I guard against this? How do I check for an empty tag?\[code\]<USTrade><CreditorId><CustomerNumber>xxxx</CustomerNumber><Name></Name><Industry code="FY" description="Factor"/></CreditorId><DateReported format="MM/CCYY">02/2012</DateReported><AccountNumber>54000</AccountNumber><HighCreditAmount>0000299</HighCreditAmount><BalanceAmount>0000069</BalanceAmount><PastDueAmount>0000069</PastDueAmount><PortfolioType code="O" description="Open Account (30, 60, or 90 day account)"/><Status code="5" description="120 Dys or More PDue"/> <Narratives><Narrative code="GS" description="Medical"/><Narrative code="CZ" description="Collection Account"/></Narratives></USTrade><USTrade>\[/code\]So, when I use:\[code\] NodeList nm = docElement.getElementsByTagName("Name"); if (nm.getLength() > 0) name = nullIfBlank(((Element) nm.item(0)) .getFirstChild().getTextContent());\[/code\]Nodelist gives a length of 1, because there is a tag, but when I do getTextContent(), it hits the null pointer because FirstChild() doesn't return anything for tag = Name And, I have done this for each xml tag. Is there a simple check I can do before every tag extraction?
 
Back
Top