java dom解析器-如何检查元素是否为空
我正在尝试解析一个 xml 文件,其中有一个组元素“专利受让人”,其中包含一些元素 - 名称、地址1、地址2、城市、州、邮政编码、国家/地区。
虽然“name”和“address1”的值始终存在,但其他元素可能有值,也可能没有值。
我已导航到单个专利受让人元素,现在想要检查该记录是否具有 address2 (和其他字段)的值。
下面给出一些相关代码——
el_patentassignees= (Element) npassignee.item(ncount);
//now el_patentassignee has in it the content of one patent assignee element
el_assigneeaddress2= (Element) el_patentassignees.getElementsByTagName("address2").item(0);
val_assigneeaddress2= el_assigneeaddress2.getTextContent();
I am trying to parse an xml file in which there is a group element "patent-assignee" which contains some elements- name, address1, address2,city,state, postcode, country.
While values will always be there for "name" and "address1" the other elements may or may not have values.
I have navigated to a single patent-assignee element, and now want to check if this record has value for address2 (and other fields) or not.
Some relevant code is given below--
el_patentassignees= (Element) npassignee.item(ncount);
//now el_patentassignee has in it the content of one patent assignee element
el_assigneeaddress2= (Element) el_patentassignees.getElementsByTagName("address2").item(0);
val_assigneeaddress2= el_assigneeaddress2.getTextContent();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
迭代
el_assigneeaddress2
的所有子节点,然后,如果您看到Text
节点,则取值:Iterate through all child nodes of
el_assigneeaddress2
, then, if you see aText
node, take the value: