jsoup icon indicating copy to clipboard operation
jsoup copied to clipboard

node.attributes() converts node keyName to all lowercase.

Open nitinkcv opened this issue 13 years ago • 6 comments

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
}

nitinkcv avatar May 06 '13 09:05 nitinkcv

See also: https://github.com/jhy/jsoup/issues/29, https://github.com/jhy/jsoup/issues/272

edgar-philipp avatar May 24 '13 09:05 edgar-philipp

+1 For preserve tag and attributes config option .

edgar-philipp avatar May 24 '13 10:05 edgar-philipp

+1 For preserve tag and attributes config option

spuzon avatar Apr 23 '14 11:04 spuzon

You can use ParseSetttings to control case normalization now.

jhy avatar Aug 26 '16 14:08 jhy

May I know how to use ParseSettings before parsing the xml data?

surinaidu avatar Jun 19 '17 07:06 surinaidu

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

}

krystiangorecki avatar Jun 19 '17 09:06 krystiangorecki