node.attributes() converts node keyName to all lowercase.
Suppose i have the following xml node:
<foo bar="test" fooBar="test1" barFoo="test2">bar</foo>
Iterator<Attribute> itr = node.attributes().iterator();
while(itr.hasNext()){
Attribute attr = itr.next();
String attrKey = attr.getKey(); // gives foobar, barfoo instead of fooBar,barFoo
}
See also: https://github.com/jhy/jsoup/issues/29, https://github.com/jhy/jsoup/issues/272
+1 For preserve tag and attributes config option .
+1 For preserve tag and attributes config option
You can use ParseSetttings to control case normalization now.
May I know how to use ParseSettings before parsing the xml data?
If you use Parser.xmlParser() then the case is preserved by default. Setting it manually can be done this way:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.ParseSettings;
import org.jsoup.parser.Parser;
public class JsoupIssue328 {
public static void main(String[] args) {
Parser xmlParser = Parser.xmlParser();
// next line is redundant because ParseSettings.preserveCase is default for xmlParser!
xmlParser.settings(ParseSettings.preserveCase);
Document doc = Jsoup.parse("<foo bar=\"test\" fooBar=\"test1\" barFoo=\"test2\">bar</foo>", "", xmlParser);
Element node = doc.select("foo").first();
Iterator<Attribute> itr = node.attributes().iterator();
while (itr.hasNext()) {
Attribute attr = itr.next();
String attrKey = attr.getKey();
System.out.println(attrKey);
}
}
}