I have a problem while parsing my XML file. I can read all nodes except the one called "Color".
I have a node called "Color" with an attribute "l" to determine the language is frensh or english.
Can anyone help me ?
Thank you.
Paul
Here's my code in VB.Net
Expand|Select|Wrap|Line Numbers
- Dim doc As XmlDocument = New XmlDocument
- Dim v_nodelist As XmlNodeList
- doc.Load(Server.MapPath("book5.xml"))
- 'Create an XmlNamespaceManager for resolving namespaces.
- Dim v_expression As String = String.Format("//{0}:Books", "ns1")
- Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable)
- nsmgr.AddNamespace("ns1", "http://www.starstandards.org/STAR")
- nsmgr.AddNamespace("oa", "http://www.openapplications.org/oagis")
- nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
- nsmgr.AddNamespace("schemaLocation", "http://www.starstandards.org/STAR/STAR/Rev1.1/BODs/ListVehicleInventory.xsd")
- 'Create a new XmlDocument for the specified source file and load it.
- 'v_nodelist = v_xmld.SelectNodes("/ListVehicleInventory/DataArea/VehicleInventory/Invoice/Vehicle")
- v_nodelist = doc.SelectNodes(v_expression, nsmgr)
- 'Select the book node with the matching attribute value.
- Dim v_color_fr As String
- Dim v_color_en As String
- Dim v_id As String
- Dim v_title As String
- Dim v_node As XmlNode
- Dim root As XmlElement = doc.DocumentElement
- Dim v_nodelistColor As XmlNodeList
- 'Loop through the nodes
- For Each v_node In v_nodelist
- ' ID
- If v_node.Item("ID") Is Nothing Then
- v_id = ""
- Else
- v_id = v_node.Item("ID").InnerText
- End If
- ' Title
- If v_node.Item("Title") Is Nothing Then
- v_title = ""
- Else
- v_title = v_node.Item("Title").InnerText
- End If
- v_nodelistColor = v_root.SelectNodes("//ns1:List/Books/Color", nsmgr)
- For Each v_nodeS In v_nodelistColor
- ' Color Fr
- v_nodeS = v_root.SelectSingleNode("//ns1:Color[@l='fr']", nsmgr)
- If Not v_nodeS Is Nothing Then
- v_color_fr = CType(v_nodeS.InnerText, String)
- Else
- v_color_fr = ""
- End If
- ' Color En
- v_nodeS = v_root.SelectSingleNode("//ns1:Color[@l='en']", nsmgr)
- If Not v_nodeS Is Nothing Then
- v_color_en = CType(v_nodeS.InnerText, String)
- Else
- v_color_en = ""
- End If
- Next
- Response.Write("ID : " & v_id & " - Title : " & v_titre & " - Color Fr : " & v_color_fr & " - Color En : " & v_color_en & "<BR>")
- v_color_fr = ""
- v_color_en = ""
- Next
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0"?>
- <bookstore xmlns="http://www.starstandards.org/STAR"
- xmlns:oa="http://www.openapplications.org/oagis"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.starstandards.org/STAR/STAR/Rev1.1/BODs/ListVehicleInventory.xsd">
- <List>
- <Books>
- <ID>BK10001</ID>
- <Title>Harry Potter</Title>
- <Color l="fr">Blanc</Color>
- <Color l="en">White</Color>
- </Books>
- <Books>
- <ID>BK20002</ID>
- <Title>Manuella</Title>
- <Color l="fr">Jaune</Color>
- <Color l="en">Yellow</Color>
- </Books>
- <Books>
- <ID>BK30003</ID>
- <Title>Charlie's angels</Title>
- <Color l="fr">Noir</Color>
- <Color l="en">Black</Color>
- </Books>
- <Books>
- <ID>BK30004</ID>
- <Title>Charlie's angels</Title>
- <Color l="en">Green</Color>
- </Books>
- </List>
- </bookstore>