Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Java更新单个XML节点的两个属性?_Java_Xml_Xml Parsing - Fatal编程技术网

如何使用Java更新单个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

我需要以Java形式更新XML中单个节点的两个属性。我不能那样做

只需要语法

XML:-


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);