Skip to main content

70-562 Reading XML


System.Xml.XmlDocument provides methods required to access xml content directly.

We will cover reading tree-based xml, in-memory.
It is also possible to work with XMLReader/XMLWRitter classes.

THE XML Document Object Model is Tree-Based, in-memory cache, represented by the XmlDocument class.

Non-cached, forward-only, read-only accesss is done using XMLReader/XmlWriter classes.

It is also possible use Linq to XML to work with XML.

The XmlDocument class loads XML as a tree, that has a root node and mutliple child nodes.
Each Xml element corresponds to one or more nodes in the tree.
Each node except for the root node has a parent node.
All the data is loaded in memory, provides random access to individual nodes and can search for any node at will.
Three based structure represents the xml infoset. This is the data stored in teh serieallized XML format.
The API doesn't care about angle brackets and quotes, just data and it's relationship. There is a difference between the serialized xml stored on disk, and the representation in memory. You dont want to work with quotes and brackets you want to work with the in-memory tree representations.

Non-CAched XML handling, allows fast access requires less overhead, but donesnt allow radnom access to data, it's sequential access, data flows to the application in the order it appears.

Adding text within an element in the serialized reprentation will correspond to a child element in memory, this is the case for any xml element, that's how it's parsed by the xml DOM, and are represented by #Text in memory.

An attribute can't contain other attributes or other elements.

Load xML data: need to load xml data into an XmlDocuemnt object, parses persisted XML into tree-based structure in memory. This is done by first creating an XmlDocuemnt object then calling the Load method prividing a filename or a stream.

Once it's loaded it's possible to work in the tree format. To view the xml retrived in serialized format, it's possible to access the OuterXML property.
It's possible to use PreserveWhitespace property to keep the white spaces obtained from the serialized code.
The root node always contains an XML delcaoraiton, Comment, and the document element. Every element is based on the XMLNode. The docuement element equals the root node of the document.

Use the HasChildNodes property or ChildNodes property to determine and access child nodes of an element. There is no recursion.
 ChildNode.Count allows to know how many child nodes. and you can use the XMLNodeType if you're looking for specific types like text types.
You can use doc.GetElementsByTagName(name) which returns an XMLNodeList that you can iterate through.

For more general critera, use SelectNodes, or SelectSingleNode methods of XmlNode, using XPath expression.
In xpath you use "//" to search at any level beneath, and use "/" at only one level beneath.
You can use attributes as criterions in XPath, //Department[@Name="Fruits"]/ would return any node that has the Name attribute set as Fruits.
You can also use //Grocery//Department, and it would look for Department elements at many levels bellow the Grocery node.
Use XPath expression to search for specific nodes and node attributes, it will allow to retrive XMLNodeLists.

If the content includes a namespace, use the XMLNamespaceManager, otherwise a namspaced document will not return any XMLNodeLists. Even the default namespace needs to have a prefix configured in the xml namespace manager.

XMLNode.SelectSingleNode will retrive the first matching node. Once you found a node, you mgiht want to navigate to related nodes, use the ChildNodes property, the FirstChild/LastChild PreviousSibling/NextSibling, ParentNode properties.
You can use XmlNode.Attribute that returns a AttributeCollection.

Comments

Popular posts from this blog

70-562 ListView

List View is a versatile control that allows to work with a signle control rather than many smaller controls. Provides rich sorting, deleting, editing, it is one of the most flexible grid control. Design view can fill the ListView with fake data to give an overview. In designer, the configure list view link might not show, (currently a bug), to fix configure the datasource but cancel then click configure datasource again and this time click finish and the Cofnoigure ListView link will show up in the smarttag. You can choose templates, LayoutTemplate is crucial, ItemTemplate(a row is part of a table, in a list view they are called items since they don't have to correspond to a table row), AlternatingItemTemplate, ItemSeparatorTemplate, SelectedItem, EmptyItemTemplate, EditItemTemplate, InsertItemTemplate allows to customize what the user will be presented when creating an item, EmptyDataTemplate. The itemPlaceHolder and the groupPlaceHolder are important elements as the will b...

React JS Patterns

React JS is always evolving, and evolving quickly. These evolutions can be very significant ones, for example, the addition of hooks. React has a lot of code patterns, often these patterns are motivated by the DRY and/or the open-close principle. These patterns sometimes come in to replace a previous one, yet the previous ones still stays in use, as a consequence, the list of patterns keep growing. The goal of the next few posts will be to list the patterns commonly used in React JS developpement. Some patterns are more specific to JSX and I will start with these, and maybe add patterns specific to Redux.

70-562 Tracing

Tracing can be enabled from the page directive, programmatically or from the web.config. This will append the trace info to the bottom of the page. There several tables of grouped trace information: Life cycle events, controls used by page, sessions state, cookies, http reuqest headers, server variables. SessionID, Time spent in each event, and check that the events are executing in the expected order. The control tree give a hierarchy of the controls in the page, and how much the control is using in the viewstate, and render by tells how much room the control uses on the page. See cookie information. And can see the Header information incase you do any kind of header manipulation. Also see query string collection. Also see the server variables passed back and forth between the server and the client application, logon user, remote user. Enable tracing when not in production, (remember to disable it when building a release... that and the debug= true setting get forg...