第一个里面一直有段代码贴不进去,虽然它不是需要调用的代码,但这里还是贴上,以免以后疑惑。这段代码是对字符串式的xml进行解析,是我测试用的,可以不用管。然后整个环境是基于Hadoop2.x的,有些API有改变,请注意
- * @param xmlString
- * @param conf
- * @return conf
- * @throws IOException
- * @throws DocumentException
- */
- public static Configuration getXmlParse(String xmlString, Configuration conf)
- throws IOException, DocumentException {
-
- // use dom4j to parse String to xml,then parse the xml
- Document doc = DocumentHelper.parseText(xmlString);
-
- Element root = doc.getRootElement();
- String messageNum = "";
- String messageLength = "";
- for (Iterator j = root.elementIterator("property"); j.hasNext();) {
- Element property = (Element) j.next();
- if (property.element("name").getText().equals("messageNum")) {
- messageNum = property.element("value").getText();
- } else {
- messageLength = property.element("value").getText();
- }
- conf.set(messageNum, messageLength);
- }
-
- return conf;
- }
- }
复制代码
|