Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Empty Elements..Help!

Status
Not open for further replies.

AlexTekTip

Programmer
Aug 30, 2004
17
US
How do I check if an element of an XML document is empty?

I have the following code:

var vSubA = vAgsXml.document.getElementsByTagName("_f8");
vSubA = vSubA[0].firstChild.data (This line errors out when element _f8 is empty I guess because you cant assign something that does not exist).

Is there a way to check if the node is valid so I know whether to assign or not?

The below shows the XML document when the _f8 element is empty:

<?xml version="1.0" encoding="ISO-8859-1" ?>
- <XZQGL.1>
- <ZQGL.1>
<_PDL>DEV</_PDL>
<_TKN>ZQGL.1</_TKN>
<_OUT>XML</_OUT>
<_TDS>Ignore</_TDS>
<_EVT>CHG</_EVT>
<_f0>ZQGL.1</_f0>
<_f1>I</_f1>
<_f2>3800</_f2>
<_f3>STC022</_f3>
<_f4>00500</_f4>
<_f5>B</_f5>
<_f6>2174319</_f6>
<_f7>512215</_f7>
<_f8 />
<FldNbr>_f0</FldNbr>
<MsgNbr>000</MsgNbr>
<Message>Inquiry Complete</Message>
</ZQGL.1>
</XZQGL.1>

 
I'm not good at javascript xml accessing, but maybe
Code:
var vSubA = vAgsXml.document.getElementsByTagName("_f8");
vSubA = (vSubA[0].data != "") ? vSubA[0].firstChild.data : "";
You can also try forum426.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top