How may I modify a XML file without any change like attributes ordering, tag expansion and encoding? (My preference is DOM API)
如何修改XML文件,而不需要修改属性排序、标记扩展和编码?(我更喜欢DOM API)
3 个解决方案
#1
5
You could try VTD-XML.
你可以试试VTD-XML。
Since this library builds an index while keeping the file content as-is, its manipulation API will allow to "patch" your file while keeping the rest intact.
由于这个库在保持文件内容不变的情况下构建了一个索引,它的操作API将允许“修补”您的文件,同时保持其他文件的完整性。
Using the VTD-XML API, you will be able to navigate your XML like a DOM tree (even using XPath) and do some modifications (insert elements, insert attributes, etc.)
使用VTD-XML API,您将能够像DOM树一样导航XML(甚至使用XPath),并做一些修改(插入元素、插入属性等)。
#2
2
One nice option would be using decentxml
. I've successfully used it before for programmatically changing a few attributes of a hand-writen XML config file without losing the formatting. It's not DOM, though.
一个不错的选择是使用decentxml。我以前曾成功地使用它以编程方式更改手工编写的XML配置文件的一些属性,而不会丢失格式。不过,这不是DOM。
#3
0
This is not possible with DOM, since DOM does not know the attributes' order.
这在DOM中是不可能的,因为DOM不知道属性的顺序。
You could use a low-level API such as StAX, javax.xml.stream, but StAX is not exactly comfortable to use.
您可以使用低级API,如StAX、java .xml。流,但是StAX使用起来并不舒服。
#1
5
You could try VTD-XML.
你可以试试VTD-XML。
Since this library builds an index while keeping the file content as-is, its manipulation API will allow to "patch" your file while keeping the rest intact.
由于这个库在保持文件内容不变的情况下构建了一个索引,它的操作API将允许“修补”您的文件,同时保持其他文件的完整性。
Using the VTD-XML API, you will be able to navigate your XML like a DOM tree (even using XPath) and do some modifications (insert elements, insert attributes, etc.)
使用VTD-XML API,您将能够像DOM树一样导航XML(甚至使用XPath),并做一些修改(插入元素、插入属性等)。
#2
2
One nice option would be using decentxml
. I've successfully used it before for programmatically changing a few attributes of a hand-writen XML config file without losing the formatting. It's not DOM, though.
一个不错的选择是使用decentxml。我以前曾成功地使用它以编程方式更改手工编写的XML配置文件的一些属性,而不会丢失格式。不过,这不是DOM。
#3
0
This is not possible with DOM, since DOM does not know the attributes' order.
这在DOM中是不可能的,因为DOM不知道属性的顺序。
You could use a low-level API such as StAX, javax.xml.stream, but StAX is not exactly comfortable to use.
您可以使用低级API,如StAX、java .xml。流,但是StAX使用起来并不舒服。