是否可以检查所有 XML 节点父节点是否存在于某种循环中?假设我有一个参考:
myXML.sectionOne.subSectionOne.subsubSectionFive.subsubsubSectionTwo.name
我发现不仅name
节点可能不存在,而且任何数量的父节点也可能不存在。所以我一直坚持做的事情是:
if(myXML.sectionOne != undefined)
{
if(myXML.sectionOne.subSectionOne != undefined)
{
if(myXML.sectionOne.subSectionOne.subsubSectionFive != undefined)
{
if(myXML.sectionOne.subSectionOne.subsubSectionFive.subsubsubSectionTwo != undefined)
{
if(myXML.sectionOne.subSectionOne.subsubSectionFive.subsubsubSectionTwo.name != undefined)
{
}
}
}
}
}