c# create and print barcode Figure 13-9. Changed event raised after modifying an employee s information in Visual C#.NET

Maker Code 3/9 in Visual C#.NET Figure 13-9. Changed event raised after modifying an employee s information

Figure 13-9. Changed event raised after modifying an employee s information
Generate Code 39 In C#
Using Barcode creator for .NET Control to generate, create Code 39 Full ASCII image in Visual Studio .NET applications.
www.OnBarcode.com
Decode Code 39 Full ASCII In C#.NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
C HA P TER 13 WO RK ING W IT H LI NQ T O XM L
Code 128A Maker In C#
Using Barcode generation for Visual Studio .NET Control to generate, create Code 128 Code Set A image in .NET applications.
www.OnBarcode.com
Make Barcode In C#.NET
Using Barcode encoder for VS .NET Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
Dealing with White Space
QR Code Drawer In Visual C#
Using Barcode generator for Visual Studio .NET Control to generate, create QR image in .NET framework applications.
www.OnBarcode.com
EAN 13 Encoder In Visual C#.NET
Using Barcode encoder for VS .NET Control to generate, create EAN-13 image in Visual Studio .NET applications.
www.OnBarcode.com
The behavior of white spaces can be controlled when you call the Load(), Parse(), and Save() methods on XElement or XDocument. The Load() and Parse() methods provide overloads that accept a parameter of type LoadOptions. The LoadOptions enumeration allows you to specify whether or not to preserve white spaces while loading the XML tree. Similarly, the Save() method provides an overload that accepts a parameter of type SaveOptions. The SaveOptions enumeration allows you to specify whether spaces should be preserved while serializing the XML tree. To illustrate the use of LoadOptions and SaveOptions enumerations, let s develop an application like the one shown in Figure 13-10.
Encoding Universal Product Code Version A In Visual C#
Using Barcode generator for .NET framework Control to generate, create UPC-A Supplement 2 image in .NET applications.
www.OnBarcode.com
GS1 - 8 Creation In C#.NET
Using Barcode creation for .NET framework Control to generate, create EAN-8 image in VS .NET applications.
www.OnBarcode.com
Figure 13-10. Application to demonstrate white space handling The application loads the Employees.xml file when you click the Load button. The Preserve White Spaces check box indicates whether we wish to preserve white spaces during document loading and saving. The Click event handler of the Load button is shown in Listing 13-20. Listing 13-20. Using LoadOptions and SaveOptions Enumerations private void button1_Click(object sender, EventArgs e) { XElement root = null; string path=Application.StartupPath + @"\employees.xml"; if (!checkBox1.Checked) { root=XElement.Load(path, LoadOptions.None); MessageBox.Show(root.ToString()); root.Save(path, SaveOptions.None); } else { root=XElement.Load(path, LoadOptions.PreserveWhitespace); MessageBox.Show(root.ToString()); root.Save(path, SaveOptions.DisableFormatting); } }
Paint Code 3 Of 9 In Objective-C
Using Barcode printer for iPad Control to generate, create Code-39 image in iPad applications.
www.OnBarcode.com
Code-39 Reader In .NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
CHAPTER 13 WORKING WITH LINQ TO XML
EAN-13 Generator In Objective-C
Using Barcode generation for iPad Control to generate, create EAN / UCC - 13 image in iPad applications.
www.OnBarcode.com
Data Matrix 2d Barcode Drawer In Visual Basic .NET
Using Barcode generator for .NET framework Control to generate, create DataMatrix image in .NET applications.
www.OnBarcode.com
The code loads the Employees.xml file into an instance of the XElement class. Depending on the check box state, it decides the appropriate LoadOptions value. The value of None indicates that we do not intend to preserve insignificant white spaces, where the value of PreserveWhitespace indicates that we wish to preserve white spaces. Similarly, while saving the document back to the disk, the SaveOptions value governs the white space behavior. The value of None indicates that the document will be indented, and insignificant white spaces will not be preserved, whereas the value of DisableFormatting indicates that we do not want to indent the document, and white spaces will be preserved as they are. The XML content loaded in the XElement are displayed in a message box using the ToString() method of the XElement class. Try running the application with the check box unchecked (see Figure 13-11) and checked (see Figure 13-12). Notice that the message box in Figure 13-12 has preserved the white spaces.
Decode Barcode In C#
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
QR Generator In None
Using Barcode printer for Font Control to generate, create QR Code ISO/IEC18004 image in Font applications.
www.OnBarcode.com
Figure 13-11. Output with LoadOptions.None
GTIN - 128 Drawer In Objective-C
Using Barcode drawer for iPad Control to generate, create UCC.EAN - 128 image in iPad applications.
www.OnBarcode.com
Printing Data Matrix 2d Barcode In Java
Using Barcode maker for BIRT reports Control to generate, create Data Matrix ECC200 image in BIRT reports applications.
www.OnBarcode.com
Note Remember that just like XML DOM, the parsing process will be affected when you preserve white space (refer to the discussion from 2 in the Dealing with White Space section). However, since LINQ to XML allows you to query the XML tree in flexible ways, white spaces will not create any problem as long as you are not relying on the count of elements in your logic.
Painting Code 128 In VS .NET
Using Barcode generation for ASP.NET Control to generate, create ANSI/AIM Code 128 image in ASP.NET applications.
www.OnBarcode.com
Code 128 Code Set B Creator In None
Using Barcode drawer for Online Control to generate, create Code 128C image in Online applications.
www.OnBarcode.com
C HA P TER 13 WO RK ING W IT H LI NQ T O XM L
Create UCC - 12 In None
Using Barcode printer for Font Control to generate, create EAN / UCC - 13 image in Font applications.
www.OnBarcode.com
Barcode Drawer In Visual Basic .NET
Using Barcode creator for VS .NET Control to generate, create Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Figure 13-12. Output with LoadOptions.PreserveWhitespace
Dealing with Namespaces
At times the XML data that you are processing might be using XML namespaces. In such cases you may want to find out information about the namespace the XML data is using. The Name property of the XElement class provides a convenient place to obtain all the information about namespaces. To illustrate the use of the Name property we will create an application as shown in Figure 13-13.
Figure 13-13. Obtaining namespace information The application consists of a Load button that loads the Employees.xml file. The namespace details are then displayed in the Label controls. In this example we will use the Employees.xml file from Listing 2-21 in 2. A part of the complete file is provided in Listing 13-21.
CHAPTER 13 WORKING WITH LINQ TO XML
Listing 13-21. Employees.xml with a Namespace <emp:employees xmlns:emp="http://www.somedomain.com"> <emp:employee employeeid="1"> <emp:firstname>Nancy</emp:firstname> <emp:lastname>Davolio</emp:lastname> <emp:homephone>(206) 555-9857</emp:homephone> Various markup tags of this listing are namespace qualified. The Click event handler of the Load button is shown in Listing 13-22. Listing 13-22. Using the Name Property to Obtain Namespace Information private void button1_Click(object sender, EventArgs e) { XElement root = XElement.Load(Application.StartupPath + @"\employees.xml"); label4.Text = root.Name.NamespaceName; label5.Text = root.Name.LocalName; label6.Text = root.Name.ToString(); } The code loads the Employees.xml file in an instance of the XElement class. The Name property of XElement is of type XName. The Namespace property of XName class gives the complete namespace name. The LocalName gives the name of the elements without the namespace qualifier, for example, employee, whereas calling the ToString() method returns the element name along with the namespace qualifier. Notice how the namespace-qualified element name is shown in Figure 13-13. The namespace is enclosed in braces ( { and } ) followed by the local name of the element.
Copyright © OnBarcode.com . All rights reserved.