【发布时间】:2019-09-13 15:41:14
【问题描述】:
你认为正确的 XPath 是在下面拉出都柏林核心标识符吗?
我添加了一个包含这些条目的命名空间管理器:
// Add the namespace.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(m_xml.NameTable);
nsmgr.AddNamespace("mets", "http://www.loc.gov/METS/");
nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
nsmgr.AddNamespace("dcterms", "http://purl.org/dc/terms/");
我已经尝试了 15 种左右不同的 XPath 迭代,包括以下迭代。当我没有收到错误时,结果为空。
//xml_uuid = m_xml.SelectSingleNode("/mets:mets/mets:dmdSec/mets:mdWrap/mets:xmlData/dcterms:dublincore/dc:identifier").Value;
xml_uuid = m_xml.SelectSingleNode("//dc:identifier",nsmgr).Value;
这是我正在使用的 xml:
<mets:mets xmlns:mets="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/version18/mets.xsd">
<mets:metsHdr CREATEDATE="2017-03-08T20:13:27" />
<mets:dmdSec ID="dmdSec_1">
<mets:mdWrap MDTYPE="DC">
<mets:xmlData>
<dcterms:dublincore xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xsi:schemaLocation="http://purl.org/dc/terms/ http://dublincore.org/schemas/xmls/qdc/2008/02/11/dcterms.xsd">
<dc:identifier>F2015.5</dc:identifier>
</dcterms:dublincore>
</mets:xmlData>
</mets:mdWrap>
</mets:dmdSec>
etc...
我正在尝试将 dc:identifier - 在这种情况下为 F2015.5 - 分配给一个字符串。
【问题讨论】:
-
如果您已将
dc前缀绑定到命名空间 URI"http://purl.org/dc/elements/1.1/",则 XPath 表达式没有问题。见xpathtester.com/xpath/e5192bd8b00933c828aea65be940b6de