我想通过 skos:Concept 访问 children 。 getChildren("skos:Concept") 和 getChildren("Concept") 都给了我一个空列表,我应该使用什么?
我的示例数据:
<owl:AnnotationProperty rdf:about="&dc;identifier"/>
<owl:ObjectProperty rdf:about="&skos;narrower"/>
<skos:Concept rdf:about="#concept:0_acetylpantolactone:4253501">
<skos:prefLabel xml:lang=""
>0-acetylpantolactone</skos:prefLabel>
<skos:hiddenLabel xml:lang=""
>2(3H)-Furanone, 3-(acetyloxy)dihydro-4,4-dimethyl-, (R)-</skos:hiddenLabel>
<dc:identifier rdf:resource="urn:CHID:028227363"/>
<dc:identifier rdf:resource="urn:MESH:C014305"/>
</skos:Concept>
<skos:Concept rdf:about="#concept:1012S:4202655">
<skos:prefLabel xml:lang="">1012S</skos:prefLabel>
<skos:hiddenLabel xml:lang="" >C19-H16-Cl2-N6-O</skos:hiddenLabel>
<skos:hiddenLabel xml:lang="">Compound 1012S</skos:hiddenLabel>
<dc:identifier rdf:resource="urn:CAS:95211_91_9"/>
<dc:identifier rdf:resource="urn:CHID:095211919"/>
</skos:Concept>
最佳答案
根据 getChildren(String) 的 javadoc:“这将返回一个列表,其中包含直接嵌套在该元素内(具有给定本地名称且不属于任何 namespace )的所有子元素(一层深)”。我认为问题是你的元素有一个命名空间,你应该使用 getChildren(String, Namespace):
Namespace ns = Namespace.getNamespace("skos", [String uri]);
List l = elem.getChildren("Concept", ns);
关于java - 通过 jdom 访问具有给定名称的子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2514892/