在perl中使用LibXML的setData()方法后,数据没有写出到实际的xml文件中
我对 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 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.