How to Get the Subset of XML

How to Get the Subset of XML thumbnail
XML can capture streaming data and save it.

Extensible Markup Language (XML) allows programmers to save hierarchical data in a series of nodes. For example, you might use XML to save information about a car dealership. The top of the hierarchy would contain the dealership. You might place nodes for each department, such as sales, repairs and accounting within the dealership node. These nested nodes form a subset of the larger dealership node. Programmers can get a subset of XML data using almost any programming language. You can easily adopt the following code sample, written in the popular C# programming language, for use in any programming framework.

Instructions

    • 1

      Open the development environment appropriate for your programming language.

    • 2

      Load the XML file into memory:

      XmlTextReader sampleReader =
      new XmlTextReader(Application.StartupPath + @"\sampleXMLFile.xml");

    • 3

      Create a "While" statement. Read the XML document within the While statement:

      while (sampleReader.Read())
      {
      if (sampleReader.NodeType == XmlNodeType.Element)
      {
      }
      }

    • 4

      Evaluate each node within an "If" statement to see if it contains the subset of XML you intend to retrieve:

      if (reader.Name == "employees")
      {
      //use the subset of XML as appropriate for your application
      }

    • 5

      Save and test your work to ensure it performs as expected.

Related Searches:

References

Resources

  • Photo Credit Thinkstock Images/Comstock/Getty Images

Comments

Related Ads

Featured