Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.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_Android - Fatal编程技术网

Java 使用XML字符串

Java 使用XML字符串,java,android,Java,Android,我需要解析现有的XML字符串(从数据库中检索)并创建新字符串存储在数据库中 我不需要完整的文档解析(我知道怎么做)-我只需要解析表单中的单个文档元素 <rootElement><childElement1>value</childElement1><childElement2>value</childElement2>...</rootElement> valuevalue。。。 它是保存为db文本字段的单个字符串,每个

我需要解析现有的XML字符串(从数据库中检索)并创建新字符串存储在数据库中

我不需要完整的文档解析(我知道怎么做)-我只需要解析表单中的单个文档元素

<rootElement><childElement1>value</childElement1><childElement2>value</childElement2>...</rootElement>
valuevalue。。。
它是保存为db文本字段的单个字符串,每个子项都是唯一的(无重复)

对于解析(在伪代码中),我正在寻找类似

String xmlString = "<rootElement><helloElement>Hello</helloElement></rootElement>";
SomeParserClass xmlStringParser = new SomeParserClass("rootElement"); //Set root
String helloString = xmlStringParser.getValue("helloElement");
String xmlString=“Hello”;
SomeParserClass xmlStringParser=新的SomeParserClass(“根元素”)//扎根
字符串helloString=xmlStringParser.getValue(“helloElement”);
我还需要类似的东西来创建字符串


在C#中,我可以使用XmlTextReader和XmlTextWriter执行类似的操作—Android是否有Java等价物?

如果只处理单个元素,使用XPath将非常方便。 如果要读取或写入多个元素,甚至整个XML文件,请尝试使用DOM。
它们都包含在标准Java API中。

试试XPath,它是从Android-API级别8内置的。DOM解析或XPath都应该适合您。谢谢,在了解如何将字符串读入文档后,我用DOM实现了所需的工作方式。