简体   繁体   English

在xml文件中查找并替换一个int

[英]find and replace an int in xml file

I have a issue where i need to find and replace an int within a xml file. 我有一个需要在XML文件中查找和替换in​​t的问题。

Here is an example file: 这是一个示例文件:

<?xml version="1.0" encoding="UTF-8"?>
<Data>
<Element time="0.00000" num="10723465" />
<Element time="7.98000" num="10028736" />
<Element time="8.40000" num="94123576" />
</data>

I want to find and replace the "num" attribute. 我想查找并替换“ num”属性。 I have been able to do this with the DOM factory however it doesn't keep the order of the attributes. 我已经能够使用DOM工厂做到这一点,但是它并没有保持属性的顺序。 There must be a simpler way to find and replace the num . 必须有一种更简单的方法来查找和替换num any help would be great :) 任何帮助将是巨大的:)

Advice 1: you should use XML library to parse, nothing else, or it would be a pain. 忠告1:您应该使用XML库进行解析,别无其他,否则会很痛苦。

Information 2: order doesnt matter in XML for attributes. 信息2:属性的XML顺序无关紧要。 Then you should forget this problem: 然后,您应该忘记此问题:

See this with much more details Order of XML attributes after DOM processing 查看更多详细信息DOM处理后XML属性的顺序

Alternative: use Regex (it can work for very simple XML). 替代方案:使用Regex(它可以用于非常简单的XML)。 example in the link before 之前链接中的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM