B4J Question [Solved] Xml2Map to parse the feedburner quotes - not working

AnandGupta

Expert
Licensed User
Longtime User
Trying to use Xml2Map to parse the feedburner quotes (as an example from a post here), but not successful in getting the <description> value.

Below is the xml from feedburner,
B4X:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="0.91">
  <channel>
    <title>Today's Quote</title>
    <link>https://www.brainyquote.com/feeds/todays_quote</link>
    <description>Today's Quote from BrainyQuote.com</description>
    <language>en-us</language>
    <webMaster>bqrss@brainyquote.com (Web Master)</webMaster>
    <managingEditor>bqrss@brainyquote.com (Web Master)</managingEditor>
    <pubDate>Sun, 18 Apr 2021 00:00:00 CDT</pubDate>
    <lastBuildDate>Sun, 18 Apr 2021 00:00:00 CDT</lastBuildDate>
    <image>
      <title>Today's Quote</title>
      <url>https://www.brainyquote.com/images/rss_brainyquote.gif</url>
      <link>https://www.brainyquote.com/feeds/todays_quote</link>
      <width>88</width>
      <height>31</height>
      <description>logo</description>
    </image>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/xml" href="http://feeds.feedburner.com/brainyquote/QUOTEBR" /><feedburner:info uri="brainyquote/quotebr" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><item>
      <title>Benjamin Franklin</title>
      <description>"A penny saved is a penny earned."</description>
      <link>http://feedproxy.google.com/~r/brainyquote/QUOTEBR/~3/hAO40P2W4Xg/benjamin-franklin-quotes</link>
    <feedburner:origLink>https://www.brainyquote.com/authors/benjamin-franklin-quotes</feedburner:origLink></item>
    <item>
      <title>P. J. O'Rourke</title>
      <description>"The mystery of government is not how Washington works but how to make it stop."</description>
      <link>http://feedproxy.google.com/~r/brainyquote/QUOTEBR/~3/XTr2YxoFuYY/p-j-orourke-quotes</link>
    <feedburner:origLink>https://www.brainyquote.com/authors/p-j-orourke-quotes</feedburner:origLink></item>
    <item>
      <title>Benjamin Jowett</title>
      <description>"Never retreat. Never explain. Get it done and let them howl."</description>
      <link>http://feedproxy.google.com/~r/brainyquote/QUOTEBR/~3/HNZegB0MICI/benjamin-jowett-quotes</link>
    <feedburner:origLink>https://www.brainyquote.com/authors/benjamin-jowett-quotes</feedburner:origLink></item>
    <item>
      <title>Milton Friedman</title>
      <description>"We have a system that increasingly taxes work and subsidizes nonwork."</description>
      <link>http://feedproxy.google.com/~r/brainyquote/QUOTEBR/~3/ne6SVRv9kS8/milton-friedman-quotes</link>
    <feedburner:origLink>https://www.brainyquote.com/authors/milton-friedman-quotes</feedburner:origLink></item>
  </channel>
</rss>

And below is the code of B4J (actually B4XPages project)
B4X:
    Log(cHtm)

'    https://www.b4x.com/android/forum/threads/saxparser-with-wait-for.117673/post-736285
'    Don't use SaxParser directly.
'    Use Xml2Map.

    Dim mQuote As Map
    Dim parser As Xml2Map
    parser.Initialize

    mQuote = parser.Parse(cHtm)
    For Each k As String In mQuote.Keys
        Log("key: " & k)
    Next
    For Each v As String In mQuote.Values
        Log("value: " & v)
        cHtm = v
    Next

Log output is
B4X:
key: rss
value: {Attributes={xmlns:feedburner=http://rssnamespace.org/feedburner/ext/1.0, version=0.91}, channel={title=Today's Quote, link=https://www.brainyquote.com/feeds/todays_quote, description=Today's Quote from BrainyQuote.com, language=en-us, webMaster=bqrss@brainyquote.com (Web Master), managingEditor=bqrss@brainyquote.com (Web Master), pubDate=Sun, 18 Apr 2021 00:00:00 CDT, lastBuildDate=Sun, 18 Apr 2021 00:00:00 CDT, image={title=Today's Quote, url=https://www.brainyquote.com/images/rss_brainyquote.gif, link=https://www.brainyquote.com/feeds/todays_quote, width=88, height=31, description=logo}, atom10:link=[{Attributes={xmlns:atom10=http://www.w3.org/2005/Atom, rel=self, type=application/xml, href=http://feeds.feedburner.com/brainyquote/QUOTEBR}, Text=}, {Attributes={xmlns:atom10=http://www.w3.org/2005/Atom, rel=hub, href=http://pubsubhubbub.appspot.com/}, Text=}], feedburner:info={Attributes={uri=brainyquote/quotebr}, Text=}, feedburner:browserFriendly=This is an XML content feed. ...


Please help.

Regards,

Anand
 

AnandGupta

Expert
Licensed User
Longtime User
If it doesn't help then post the output.

The feedburner gives a XML string. I did tried to put it in "https://b4x.com:51041/json/index.html" but got error,
"Error parsing string:​
java.lang.StringIndexOutOfBoundsException: String index out of range: 3030"​

B4X:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="0.91">
  <channel>
    <title>Today's Quote</title>
...

b4a1.png


I put the xml string in "https://jsonformatter.org/xml-parser"
b4a2.png

It did parse as required and showed the " description" tag whose value I want.

Please guide, how to get it in B4J-B4XPages.

Regards,

Anand
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
You need to post the output of jg.ToPrettyString. This will be a json string.
Thanks a lot ?

B4X:
"Experience is simply the name we give our mistakes."
"A penny saved is a penny earned."
"The mystery of government is not how Washington works but how to make it stop."
"Never retreat. Never explain. Get it done and let them howl."

Regards,

Anand
 
Upvote 0
Top