c# - How to read YML feeds - or ignore DOCType if read as XML -


ok hope isn t confusing here goes.

we have been provided feed russian retailer in yml format need read , enter database. haven t used yml before , honest don't understand or how differs xml (which prefer using unfortunately retailer won t supply in format). have tried google how read yml file , come across yaml file have been supplied not like.

so have not had luck finding yml have downloaded xml , tried read following line added:

<!doctype yml_catalog system "shops.dtd"> 

and because of cannot read nodes - have manually deleted line , can read nodes want to.

here snippet of file:

before download:

<yml_catalog date="2013-08-28 14:50"> <shop> <name>domprom.ru</name> <company>domprom.ru</company> <url>http://www.domprom.ru</url> <currencies> <currency id="rub" rate="1"/> <currency id="usd" rate="33.4"/> <currency id="eur" rate="37.1"/> </currencies> <categories> <category id="28">Крупная бытовая техника</category> <category id="29" parentid="28">Стиральные машины</category>    </categories> <offers> <offer id="27232" type="vendor.model" available="true"> 

after download:

<?xml version="1.0" encoding="windows-1251"?><!doctype yml_catalog system "shops.dtd"> <yml_catalog date="2013-08-28 17:00"> <shop> <name>domprom.ru</name> <company>domprom.ru</company> <url>http://www.domprom.ru</url> <currencies> <currency id="rub" rate="1"/> <currency id="usd" rate="33.4"/> <currency id="eur" rate="37.1"/> </currencies> <categories> <category id="28">Êðóïíàÿ áûòîâàÿ òåõíèêà</category> <category id="29" parentid="28">Ñòèðàëüíûå ìàøèíû</category> <category id="30" parentid="28">Ïîñóäîìîå÷íûå ìàøèíû</category> <category id="31" parentid="28">Õîëîäèëüíèêè/Ìîðîçèëüíûå êàìåðû/Âèííûå øêàôû</category> </categories> <offers> <offer id="27232" type="vendor.model" available="true"> 

here of code i'm usingf read it:

var document = new xmldocument();              try             {                 // , load contents of file                 document.load(downloadfilename);             }             catch (exception ex)             {                 _keepitdry.writetoeventlog(ex);                 // trying catch going on while progrem trying load downloaded file                 _keepitdry.addtolistbox(datetime.now.tolongdatestring() + datetime.now.tolongtimestring() + " error loading file " + scrape.retailer.description + " : " + ex.message + " " + ex.stacktrace, _listboxlog);         }     var dompromnodes = document.selectnodes("//yml_catalog//shop//offers/offer");                     if (dompromnodes != null)                     {                         foreach (xmlnode node in dompromnodes)                         {                             var title = "no title"; var price = "no price"; var modelno = "no modelno"; var sku = "no sku"; var instock = "no instock";                             var deeplink = "no deeplink"; var imageurl = "no imageurl"; var brand = "no brand"; 

if doctype line taken out var dompromnodes = document.selectnodes("//yml_catalog//shop//offers/offer"); return results otherwise fails.

any or pointer yml appreciated or way remove or ignore

thanks

to ignore doctype making me unable see nodes added following:

  xmldocument doc = new xmldocument();                     doc.loadxml(regex.replace(file.readalltext(downloadfilename), "<!doctype.+?>", string.empty)); 

so removed doctype line , allowed me read nodes


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -