Resolution of colon reading problem in xml

  • 2020-05-05 11:48:14
  • OfStack

Reference articles: http: / / chs gotdotnet. com quickstart/howto doc/Xml/XmlNameSpace aspx

I source:
                public   void   bindXml(string   xmlUrl)
                {
                        System.Xml.XmlDocument   doc   =   new   System.Xml.XmlDocument();
                        doc.Load(   System.AppDomain.CurrentDomain.BaseDirectory+"kkjj.xml");
                        //doc.Load(xmlUrl);
                        doc.SelectNodes("/rss/channel");
                        System.Xml.XmlNode   root   =   doc.DocumentElement;
                        System.Xml.XmlNode   xn   =   root.SelectSingleNode("/rss/channel");
                outStr   +=   "album name:"   +   xn SelectSingleNode("title") InnerText; // album name
                        outStr   +=   " < br > url: "  +   xn.SelectSingleNode("link").InnerText; // photo album url
                        outStr   +=   " < br > Photo album image: < img   src='"   +   xn.SelectSingleNode("image/url").InnerText   +   "'   / > "; // photo album home page picture

                        //outStr   +=   " < br > < img   src='"   +   xn.SelectNodes("item")[0].SelectSingleNode("enclosure").Value   +   "' > ";
                        System.Xml.XmlNodeList   xnl   =   xn.SelectNodes("item");
                        outStr   +=   " < br > Number of pictures in the album: "  +   xnl.Count.ToString ()   +   ";

                        System.Xml.XmlNamespaceManager   nsmanager   =   new   System.Xml.XmlNamespaceManager(doc.NameTable);
                        nsmanager.AddNamespace("media",   "http://search.yahoo.com/mrss/");

                  //   create a string containing   XPATH   expression to evaluate.
                        string   exprString   =   String.Format("//   {0}:group",   "media");

                        System.Xml.XmlNodeList   nodelist   =   doc.SelectNodes(exprString,   nsmanager);

                        outStr   +=   " < br > media:title:"+nodelist[0].SelectSingleNode("media:title",nsmanager).Attributes["type"].InnerText;





//                         for(int   i=0;i < xnl.Count;i++)
//                         {
//                                 outStr   +=   " < br >   < img   src='"+xnl[i].SelectSingleNode("enclosure").Attributes["url"].InnerText+"'   / > ";
//                         }
                }

Then I saw... gg xml has a colon in it, so kaka has solved it.
Pay xml fragment

-   < media:group >
    < media:title   type="plain" > 02.JPG < /media:title >  
    < media:description   type="plain"   / >  
    < media:keywords   / >  
    < media:thumbnail   url="http://lh3.google.com/pengpengsay/R3C96dqJBUI/AAAAAAAAAEo/j3csPO0ig7o/s72/02.JPG"   height="48"   width="72"   / >  
    < media:thumbnail   url="http://lh3.google.com/pengpengsay/R3C96dqJBUI/AAAAAAAAAEo/j3csPO0ig7o/s144/02.JPG"   height="96"   width="144"   / >  
    < media:thumbnail   url="http://lh3.google.com/pengpengsay/R3C96dqJBUI/AAAAAAAAAEo/j3csPO0ig7o/s288/02.JPG"   height="192"   width="288"   / >  
    < media:content   url="http://lh3.google.com/pengpengsay/R3C96dqJBUI/AAAAAAAAAEo/j3csPO0ig7o/02.JPG"   height="400"   width="600"   type="image/jpeg"   medium="image"   / >  
    < media:credit > Fresh-from-stats-class < /media:credit >  
    < /media:group >

xml address: http: / / picasaweb google. com pengpengsay/lNFxFK

Related articles: