Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.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属性中解析int_Java - Fatal编程技术网

Java 从XML属性中解析int

Java 从XML属性中解析int,java,Java,我有一个节点的属性,它包含如下内容: number=“1” 我想如果我在=上解析,我就可以使用Integer.parseInt(node.getAttributes().item(i.toString()) 但这将返回以下错误: java.lang.NumberFormatException: For input string: ""1"" 所以现在我在做: String[] value = node.getAttributes().item(i).toString().split("=\""

我有一个节点的属性,它包含如下内容: number=“1”

我想如果我在
=
上解析,我就可以使用
Integer.parseInt(node.getAttributes().item(i.toString())

但这将返回以下错误:

java.lang.NumberFormatException: For input string: ""1""
所以现在我在做:

String[] value = node.getAttributes().item(i).toString().split("=\"");
String[] number = value[1].split("\"");
Integer.parseInt(number[0].toString()) // contains the right value 1
有没有更好更干净的方法?我觉得这太俗气了

编辑:

节点的定义如下: org.w3c.dom.Node Node=nodeList.item(索引)

更换

node.getAttributes().item(i).toString()


节点的类型/类别是什么?哦,对不起!org.w3c.dom.Node Node=nodeList.item(索引)您使用了哪个api?xml?您无法获取属性的值?解决问题的顺序:供应商文档=>Dr.Google=>StackOverflow
node.getAttributes().item(i).getNodeValue()