在perl中使用LibXML的setData()方法后,数据没有写出到实际的xml文件中

发布于 2025-01-05 01:28:54 字数 393 浏览 4 评论 0原文

我对 perl 中 libXML 的 setData 方法有疑问。这是我的代码片段:

    print "\n Query: " , $query, "\n";  #Query
    my($exactNode) = $doc->findnodes($query);  #Finding the nodes who data needs to change
    print "\n Data: ", $exactNode->setData($finalString), "\n";  #Setting the data

使用 setData 之后,我使用 getData 来检索值。 getData 输出的值是最新的,但是当我打开 xml 时应该设置该数据。价值是旧的。

请告诉我我做错了什么。

I have an issue with the setData method of libXML in perl. Here is my code snippet:

    print "\n Query: " , $query, "\n";  #Query
    my($exactNode) = $doc->findnodes($query);  #Finding the nodes who data needs to change
    print "\n Data: ", $exactNode->setData($finalString), "\n";  #Setting the data

After using the setData I used getData to retrieve the value. The value outputted by getData is the latest one but when I open the xml where this data should be set. The value is the old.

Please advise what am I doing wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

翻了热茶 2025-01-12 01:28:54

我对 LibXML 不太熟悉,但 setData 据记录不返回任何内容。您可能必须调用 setData() 然后单独检索它。

我也不相信 LibXML 会为您保存更改。您可能必须显式保存修改后的 XML 文档,可能使用 toFile。请参阅 XML::LibXML::Document

I'm not too familiar with LibXML, but setData is documented to return nothing. You probably have to call setData() and then retrieve it separately.

I also do not believe the LibXML will save changes for you. You likely have to explicitly save the modified XML document, probably with toFile. See XML::LibXML::Document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文