Based on this .xml i try to get the photos from every article:
<?xml version="1.0" encoding="UTF-8"?>
<articles>
<article hint="0">
<id>498940</id>
<type>1</type>
<category>International</category>
<title>
<![CDATA[News title 1]]>
</title>
<description>
<![CDATA[News Description 2]]>
</description>
<content>
<photos is3idfp="CMS_12_498940" is3fechapub="2015-03-26 15:53:54">
<photo>
<photoURL>http://static01.nyt.com/images/2015/03/27/world/27IRAQ/27IRAQ-master675.jpg</photoURL>
<photodescription>
<![CDATA[U.S. Airstrikes on ISIS in Tikrit Prompt Boycott by Shiite Fighters]]>
</photodescription>
</photo>
<photo>
<photoURL>http://static01.nyt.com/images/2015/03/26/world/alps-web/26plane10-master675.jpg</photoURL>
<photodescription>
<![CDATA[Challenges Weigh Heavily on Recovery Efforts in Germanwings Crash]]>
</photodescription>
</photo>
<photo>
<photoURL>http://static01.nyt.com/images/2015/03/26/world/26Yemen3/26Yemen3-master180.jpg</photoURL>
<photodescription>
<![CDATA[Saudi Arabia Leads Air Assault in Yemen]]>
</photodescription>
</photo>
</photos>
</content>
</article>
<article hint="0">
<id>498941</id>
<type>5</type>
<title>
<![CDATA[Advertisement]]>
</title>
<urlAd>http://ads.google.com/RealMedia/ads/adstream_nx.ads/(random)@x31</urlAd>
</article>
<article hint="0">
<id>498940</id>
<type>1</type>
<category>International</category>
<title>
<![CDATA[News title 2]]>
</title>
<description>
<![CDATA[News Description 2]]>
</description>
<content>
<photos is3idfp="CMS_12_498940" is3fechapub="2015-03-26 15:53:54">
<photo>
<photoURL>http://static01.nyt.com/images/2015/03/27/sports/Y-JACKSON/Y-JACKSON-master675.jpg</photoURL>
<photodescription>
<![CDATA[Wisconsin Guard Carries an N.B.A. Pedigree, but Is Inspired by His Mother]]>
</photodescription>
</photo>
<photo>
<photoURL>http://static01.nyt.com/images/2015/03/27/sports/LOVE/LOVE-master675.jpg</photoURL>
<photodescription>
<![CDATA[Kevin Love Shows What He Can Do as Cavaliers See What They Can Be]]>
</photodescription>
</photo>
<photo>
<photoURL>http://static01.nyt.com/images/2015/03/26/sports/CITY-KNICKS/CITY-KNICKS-blog427.jpg</photoURL>
<photodescription>
<![CDATA[Knicks Approach a Franchise Record With a Pounding From the Clippers]]>
</photodescription>
</photo>
</photos>
</content>
</article>
</articles>
getting a dataset from the xml:
string sourceXML = "http://mydomain/myxmlfile.xml";
XmlReader xmlFile = XmlReader.Create(sourceXML, new XmlReaderSettings());
DataSet ds = new DataSet();
ds.ReadXml(xmlFile);
i get four tables:
ds.Tables[0].TableName, article
ds.Tables[1].TableName, content
ds.Tables[2].TableName, photos
ds.Tables[3].TableName, photo
so i try to parse and i get the articles but all the pictures:
1 title: News title 1
1 title: News Description 2
http://static01.nyt.com/images/2015/03/27/world/27IRAQ/27IRAQ-master675.jpg
http://static01.nyt.com/images/2015/03/26/world/alps-web/26plane10-master675.jpg
http://static01.nyt.com/images/2015/03/26/world/26Yemen3/26Yemen3-master180.jpg
http://static01.nyt.com/images/2015/03/27/sports/Y-JACKSON/Y-JACKSON-master675.jpg
http://static01.nyt.com/images/2015/03/27/sports/LOVE/LOVE-master675.jpg
http://static01.nyt.com/images/2015/03/26/sports/CITY-KNICKS/CITY-KNICKS-blog427.jpg
1 title: News title 2
1 title: News Description 2
http://static01.nyt.com/images/2015/03/27/world/27IRAQ/27IRAQ-master675.jpg
http://static01.nyt.com/images/2015/03/26/world/alps-web/26plane10-master675.jpg
http://static01.nyt.com/images/2015/03/26/world/26Yemen3/26Yemen3-master180.jpg
http://static01.nyt.com/images/2015/03/27/sports/Y-JACKSON/Y-JACKSON-master675.jpg
http://static01.nyt.com/images/2015/03/27/sports/LOVE/LOVE-master675.jpg
http://static01.nyt.com/images/2015/03/26/sports/CITY-KNICKS/CITY-KNICKS-blog427.jpg
I´d like to obtain only the photos for every article, this is what i've tried:
foreach (DataRow row in ds.Tables[0].Rows)
{
try
{
string element = row["type"].ToString();
article = new Article();
feed += element + " title: " + row["title"] + Environment.NewLine;
feed += element + " title: " + row["description"] + Environment.NewLine;
article.setTitle("<![CDATA[" + row["title"].ToString() + "]]>");
foreach (DataRow row1 in ds.Tables[3].Rows)
{
feed += row1["photoURL"] + Environment.NewLine;
}
listArt.Add(article);
i++;
}
catch (IndexOutOfRangeException ioe)
{
feed += "Error al crear " + sourceXML + Environment.NewLine;
feed += ioe.ToString() + Environment.NewLine;
}
}
textBox1.AppendText(feed);