0

I'm trying to load a xml (from a webservice) into a dataset. My issue is the xml doesnt always has the same structure.

it look like this

<Articles> 
   <Article>
      <id>7156</id>
      <name>FirstArticle</name>
      <pic>zaea.jpg </pic>
   </Article>
   <Article>
      <id>7157</id>
      <name>Second</name>
   </Article>
<Articles>

As you see first node has a "pic" the seconde hasnt. My problem is it will only load the first node into the dataset because "it has all property". If a node is missing one property it wont load it into dataset...

Here's what I do

Dim dataSet As New DataSet()
Dim httpResponse As String
httpResponse = HttpRequest.WRequest("WEBSERVICE URL")
Dim xmlSR As System.IO.StringReader = New System.IO.StringReader(httpResponse)
dataSet.ReadXml(xmlSR)

I allready try to add the column of the dataset before loading data but it doesnt change anything...

How can I do that? Thanx

2 Answers2

0

In my opinion that XML structure is not valid. Properties should not be avoided when there is no value, You should consider writing </pic> or even <pic></pic> in the second article element

Alex
  • 2,247
  • 1
  • 27
  • 37
0

Try

dataSet.ReadXml(xmlSR,XmlReadMode.IgnoreSchema)

If there were a schema for this it would have to use the <xsl:choose> condition.

Nigel B
  • 3,577
  • 3
  • 34
  • 52