我正在尝试使用libxml2解析OSM文件。 这是osm文件的一部分:
<node id="368138" lat="48.8546445" lon="2.3627305" user="Pieren"
uid="17286" visible="true" version="3" changeset="4490579"
timestamp="2010-04-21T20:34:49Z">
<tag k="highway" v="traffic_signals"/>
</node>
我需要获取标签的键和值。但我不知道怎么做。我试图使用
进行访问xmlHasProp(node,(const xmlChar*)"tag")
但我认为标签不被视为node
的支柱。
答案 0 :(得分:0)
我不熟悉libxml2,但根据文档xmlHasProp()
搜索XML 属性。在OSM XML中,节点具有各种属性,如 lat , lon 等。然而,标签不是作为属性建模的,而是它们是子元素。要访问标记,您必须遍历节点的 children 。
答案 1 :(得分:0)
直截了当的选择是从根节点走到您正在寻找的后代节点。可以通过node
和node
指针将XML文档或元素的子节点作为链接列表进行访问。例如,假设for (xmlNode *cur = node->children; cur; cur = cur->next) {
if (cur->type == XML_ELEMENT_NODE
&& xmlStrcmp(cur->name, BAD_CAST "tag") == 0) {
/* Found "tag" element. */
}
}
是OSM <rich:dataTable value="#{publicServiceList.serviceList}"
id="serviceTable" var="_service" rows="20" reRender="ds"
sortMode="single"
columnClasses="listItemLink, listItem, listeItem, listItemLink"
headerClass="listHeader" rowClasses="odd, even"
styleClass="listHeaderBackground">
<f:facet name="header">
<rich:columnGroup>
<rich:column>
<h:outputText
value="#{messages['public.page.service_A-Z.list.title.SERVICENAME']}" />
</rich:column>
<rich:column>
<h:outputText
value="#{messages['public.page.service_A-Z.list.title.DESCRIPTION']}" />
</rich:column>
</rich:columnGroup>
</f:facet>
<rich:column filterBy="#{_service.title}" filterEvent="onkeyup"
filterValue="#{publicServiceList.currentTitleFilterValue}"
sortBy="#{_service.title}">
<s:link view="/public/PublicService.xhtml"
value="#{_service.title}" propagation="none"
id="publicServiceView">
<f:param name="serviceId" value="#{_service.id}" />
</s:link>
</rich:column>
<rich:column filterMethod="#{publicServiceList.filterDescription}">
<f:facet name="header">
<h:inputText
value="#{publicServiceList.currentDescriptionFilterValue}"
id="input">
<a4j:support event="onkeyup" reRender="serviceTable , ds"
ignoreDupResponses="true" requestDelay="700"
oncomplete="setCaretToEnd(event);" />
</h:inputText>
</f:facet>
<h:outputText value="#{_service.shortDescription}" />
</rich:column>
<f:facet name="footer">
<rich:datascroller id="ds" renderIfSinglePage="false"></rich:datascroller>
</f:facet>
元素:
<rich:dataTable value="#{publicServiceList.serviceList}"
id="serviceTable" var="_service" rows="20" reRender="ds"
sortMode="single"
columnClasses="listItemLink, listItem, listeItem, listItemLink"
headerClass="listHeader" rowClasses="odd, even"
styleClass="listHeaderBackground">
<rich:column filterBy="#{_service.title}" filterEvent="onkeyup"
filterValue="#{publicServiceList.currentTitleFilterValue}"
sortBy="#{_service.title}">
<f:facet name="header">
<h:outputText
value="#{messages['public.page.service_A-Z.list.title.SERVICENAME']}" />
</f:facet>
<s:link view="/public/PublicService.xhtml"
value="#{_service.title}" propagation="none"
id="publicServiceView">
<f:param name="serviceId" value="#{_service.id}" />
</s:link>
</rich:column>
<rich:column filterBy="#{_service.description}"
filterEvent="onkeyup"
filterValue="#{publicServiceList.currentDescriptionFilterValue}"
sortBy="#{_service.shortDescription}">
<f:facet name="header">
<h:outputText
value="#{messages['public.page.service_A-Z.list.title.DESCRIPTION']}" />
</f:facet>
<h:outputText value="#{_service.shortDescription}" />
</rich:column>
<rich:column filterBy="#{_service.keywordString}"
filterEvent="onkeyup"
filterValue="#{publicServiceList.currentKeywordFilterValue}"
sortBy="#{_service.keywordString}">
<f:facet name="header">
<h:outputText
value="#{messages['public.page.service_A-Z.list.title.KEYWORDS']}" />
</f:facet>
<h:outputText value="#{_service.keywordString}" />
</rich:column>
<rich:column filterBy="#{_service.organization}"
filterEvent="onkeyup"
filterValue="#{publicServiceList.currentOrganizationFilterValue}"
sortBy="#{_service.organization}">
<f:facet name="header">
<h:outputText
value="#{messages['public.page.service_A-Z.list.title.ORGANIZATION']}" />
</f:facet>
<s:link view="/public/PublicOrganization.xhtml"
value="#{_service.organization.organizationName}"
propagation="none" id="publicOrganizationView">
<f:param name="organizationId"
value="#{_service.organization.organizationId}" />
</s:link>
</rich:column>
<f:facet name="footer">
<rich:datascroller id="ds" renderIfSinglePage="false"></rich:datascroller>
</f:facet>
另一种选择是使用 libxml2 的XPath引擎。它允许您使用XPath表达式枚举节点。
查看 libxml2 网站上的examples。