开发者

How to add an attribute to a node so it is the first one

开发者 https://www.devze.com 2023-03-13 01:20 出处:网络
I have a Nokogiri xml node: node = <word n=\'ab\' v=\'cd\'>something</word> I want to add an attribute:

I have a Nokogiri xml node:

node = <word n='ab' v='cd'>something</word>

I want to add an attribute:

node['p']='ef'

but in such a way that it 'shows' the first in the list of attribut开发者_运维问答es, like

node = <word p='ef' n='ab' v='cd'>something</word>

Is there a simple way to do this?


I don't know of any XML serializer that allows you to control the order of attributes (except by accident, relying on undocumented features of a product). It shouldn't matter; the order is only cosmetic.

When you say "the order denotes the certitude" this is very worrying, because you are attaching meaning to the order of attributes when XML is very clear that the order will in general not be maintained. You need to redesign your XML to find a different way to capture this information.

0

精彩评论

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