Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Checking if a particular tags exists

Checking if a particular tags exists

Scheduled Pinned Locked Moved XML / XSL
helpquestionxmltutorialannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brendan Vogt
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • B Brendan Vogt

      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

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups