Checking if a particular tags exists
-
Hi, A section of my XML file looks like this: SKU001 Yellow Marker 45.0 1 SKU003 Blue Marker 10.45 1 The tags in the Product tag are the names of my table fields. This file is used to import data into the product table. So I just loop through the elements, check the ID, and update that record. I have to do a couple of checks. I do a check to see if the tag is empty because this is my primary key, then it displays an error message. But what happens if there is no ID tag for a particular records, maybe for some or other reason it was not entered into the XML file. How do I check to see if a particular tag exists? Like for example: Blue Marker 10.45 1 This is how I loop: Dim productNodes As XmlNodeList Dim productNode As XmlNode Dim baseDataNodes As XmlNodeList doc.Load(strPathFile) productNodes = doc.GetElementsByTagName("Product") For Each productNode In productNodes baseDataNodes = productNode.ChildNodes For Each baseDataNode As XmlNode In baseDataNodes Next Next Please can some one help me. Regards ma se
-
Hi, A section of my XML file looks like this: SKU001 Yellow Marker 45.0 1 SKU003 Blue Marker 10.45 1 The tags in the Product tag are the names of my table fields. This file is used to import data into the product table. So I just loop through the elements, check the ID, and update that record. I have to do a couple of checks. I do a check to see if the tag is empty because this is my primary key, then it displays an error message. But what happens if there is no ID tag for a particular records, maybe for some or other reason it was not entered into the XML file. How do I check to see if a particular tag exists? Like for example: Blue Marker 10.45 1 This is how I loop: Dim productNodes As XmlNodeList Dim productNode As XmlNode Dim baseDataNodes As XmlNodeList doc.Load(strPathFile) productNodes = doc.GetElementsByTagName("Product") For Each productNode In productNodes baseDataNodes = productNode.ChildNodes For Each baseDataNode As XmlNode In baseDataNodes Next Next Please can some one help me. Regards ma se
Normally, you create a schema that checks your XML document for invalid structure. However, you can do the following:
XmlNodeList nodes = doc.SelectNodes("/Products/Product[not(ID)]"); if (nodes.Count > 0) // throw a exception?
"We make a living by what we get, we make a life by what we give." --Winston Churchill