【发布时间】:2023-03-12 22:45:01
【问题描述】:
我有一个带有默认命名空间的 xml,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<start xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://127.0.0.1 GrammarXSD.xsd" version="01.00" xmlns="GrammarXSD.xsd">
<DataModel>
#rest of the xml
</DataModel>
</start>
为了解析这个 xml,我尝试使用以下代码注册命名空间:
my $file = "xml file location";
my $dom = XML::LibXML->load_xml(location => $file);
my $xpc = XML::LibXML::XPathContext->new($dom->documentElement());
$xpc->registerNs('ns', 'GrammarXSD.xsd');
my $b = $dom->findnodes('//ns:DataModel');
但是,这并没有按预期找到 DataModel 节点。 GrammarXSD.xsd 文件与 xml 位于同一位置。
我在这里错过了什么?
【问题讨论】:
-
您可能会发现the examples here 很有用。
标签: xml perl libxml2 xml-libxml