Hi, given the following simple XML fragment:
<country>
<code>ES</code>
<description>SPAIN</description>
<destination>
<code>IBZ</code>
<description>IBIZA</description>
</destination>
<destination>
<code>PMI</code>
<description>MALLORCA</description>
</destination>
<destination>
<code>MAH</code>
<description>MENORCA</description>
</destination>
</country>
<country>
<code>PT</code>
<description>PORTUGAL</description>
<destination>
<code>FAO</code>
<description>ALGARVE</description>
</destination>
</country>
I want to loop through "destinations" and obtain each destination code
and name, along with it's parent country code and name, in order to,
e.g. insert them into a database table.
Is there a more direct / intuitive way to program the selection of
child nodes values within a XPathNodeIterator loop than this?
XPathDocument doc = new XPathDocument(new XmlTextReader(sXmlDocument,
XmlNodeType.Document, null));
XPathNodeIterator it =
doc.CreateNavigator().Select("//response/country/destination");
XPathNodeIterator s;
while (it.MoveNext()) {
s = it.Current.Select("../code");
s.MoveNext();
CountryCode = s.Current.Value;
s = it.Current.Select("../description");
s.MoveNext();
CountryDescription = s.Current.Value;
s = it.Current.Select("code");
s.MoveNext();
DestinationCode = s.Current.Value;
s = it.Current.Select("description");
s.MoveNext();
DestinationDescription = s.Current.Value;
helper.ExecuteNonQuery(cs, "DestinationInsert", new object[] {
CountryCode, CountryDescription, DestinationCode,
DestinationDescription } );
}
Note: I didn't use "((IHasXmlNode)it.Current).GetNode()" to avoid DOM
objects
Thanks