如何使用Java更新单个XML节点的两个属性?
我需要以Java形式更新XML中单个节点的两个属性。我不能那样做 只需要语法 XML:-如何使用Java更新单个XML节点的两个属性?,java,xml,xml-parsing,Java,Xml,Xml Parsing,我需要以Java形式更新XML中单个节点的两个属性。我不能那样做 只需要语法 XML:- str201x是xpos的字符串值,我也需要为ypos输入str201y。请发布代码。@Addy我已经添加了code@umarfaraz我已经添加了代码,为什么不使用attr.getNamedItem(“ypos”).setTextContent(str201y)来跟踪它呢。。。只是想知道?@艾迪想了,但没有得到结果。这是唯一的办法吗? <control name="control_200" xpos
str201x是xpos的字符串值,我也需要为ypos输入str201y。请发布代码。@Addy我已经添加了code@umarfaraz我已经添加了代码,为什么不使用
attr.getNamedItem(“ypos”).setTextContent(str201y)来跟踪它呢代码>。。。只是想知道?@艾迪想了,但没有得到结果。这是唯一的办法吗?
<control name="control_200" xpos="233" ypos="25" width="60" type="float" format="%7.2f" refvar="gud/_ZSFR[29]" hotlink="true">
JButton btnx1y1 = new JButton(">");
btnx1y1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String filePath = "C:\\Users\\Admin\\workspace\\generator\\data\\f.xml";
File inputFile = new File(filePath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document document = dBuilder.parse(inputFile);
Node control = document.getElementsByTagName("control").item(0);
NamedNodeMap attr = control.getAttributes();
Node nodeAttr = attr.getNamedItem("xpos");
nodeAttr.setTextContent(str201x);