I ma new to java. I have a string s:
s="<name>header</name><content>Good Morning</content>"
How to get value of content and name using Jsoup? What JSoup returns when content is empty?null?
I ma new to java. I have a string s:
s="<name>header</name><content>Good Morning</content>"
How to get value of content and name using Jsoup? What JSoup returns when content is empty?null?
You can use jsoup:
Connection con2=Jsoup.connect(url);
Document doc = con2.get();
//or use Document doc = Jsoup.parse(html);
Element e=doc.head().select("meta[name=header]").first();
String url=e.attr("content");
http://jsoup.org/cookbook/extracting-data/attributes-text-html
http://jsoup.org/cookbook/extracting-data/selector-syntax
For your edit I do agree with the answer that @Hein give you.
Use this RegEx for example: name=(.*) content=(.*) \/>
. The name will be in the first group and the content in the second.
I would recommend double quotes around the strings though. In that case you can use this regex: name=\"(.*)\" content=\"(.*)\"
Edit after the OPs edit:
If you have complete control of the data yourself you should consider saving the name and content in seperate columns in your database, or look into serialization maybe.