开发者

Best way to change node value with libxml2

开发者 https://www.devze.com 2023-03-20 20:08 出处:网络
I want to change the value of a node in a given XML file as template and save the entire XML a开发者_开发技巧s another file.

I want to change the value of a node in a given XML file as template and save the entire XML a开发者_开发技巧s another file.

I must use the libxml2 library in a Linux environment and my ideas were:

  • parse the template file
  • when element found modify it
  • save the document

Can be this workflow correct?

Are there other way to do this thing with less code?

Any code example will be appreciated.

Thanks!


Another solution is to open the file in r/w mode, found the value and change it on the fly. But the problem is when the value is difficult to find.

The solution with libxml2 is to parse the file for creating a tree. The tree is a very good structure for finding a value. You can change the value in the tree and save the tree in a new file.

0

精彩评论

暂无评论...
验证码 换一张
取 消