gpt4 book ai didi

XML::简单忽略 emdash 标签?

转载 作者:数据小太阳 更新时间:2023-10-29 02:18:11 27 4
gpt4 key购买 nike

我正在使用 XML Simple 来解析 XML 文件,有问题的部分如下所示:

    <textBody>
<title>
<titlePart>
<text>SECTION A <emdash/> HUMAN NECESSITIES</text>
</titlePart>
</title>
</textBody>
<ipcEntry kind="t" symbol="A01" ipcLevel="C" entryType="K" lang="EN">
<textBody>
<title>
<titlePart>
<text>AGRICULTURE</text>
</titlePart>
</title>
</textBody>
</ipcEntry

出于某种原因,XML::Simple 完全忽略了 <text>SECTION A <emdash/> HUMAN NECESSITIES</text>我猜是因为 emdash 标签,因为 <text>AGRICULTURE</text>解析得很好。我还尝试通过以下方式设置解析器:

$XML::Simple::PREFERRED_PARSER = 'XML::Parser';

还是不行。有什么想法吗?

最佳答案

拥有一个标签,其值包括文本和其他标签被称为“混合内容”。 XML::Simple不处理混合内容(无论如何没有用)。在 XML::Simple 的世界观中,标签可以包含文本或其他标签,但不能同时包含两者。这就是为什么它被称为“简单”的原因。引用its docs :

Mixed content (elements which contain both text content and nested elements) will be not be represented in a useful way - element order and significant whitespace will be lost. If you need to work with mixed content, then XML::Simple is not the right tool for your job

您必须选择不同的 XML 模块。 XML::LibXMLXML::Twig是受欢迎的选择。

另一种可能性是让生成 XML 的人使用实体而不是标签来表示破折号等字符。例如,XML::Simple 可以处理:

<text>SECTION A &#8212; HUMAN NECESSITIES</text>

就好了。 (&#8212; 是长破折号。)

关于XML::简单忽略 emdash 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4236947/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com