XmlNode

When an XmlNode method returns an XmlNode, such as a child, is this 
generated on-the-fly or is it the actual component of the internal tree 
structure? If the parent is moved in the tree, will the pointer remain 
valid? I have looked at as much of the structure as I can using .NET 
Reflector and I think it will, but I want to be sure.

I 'm planning to add XmlNodes to the Tag property of TreeNodes in a TreeView 
to be able to persist changes back to the document and I would like to know 
if this will take up any more memory than when they are not linked in this 
way, or if it is better to generate an XPath pointer as I need it. 


0
Michael
2/3/2004 10:12:00 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
773 Views

Similar Articles

[PageSpeed] 18

Michael Hutchinson wrote:

> When an XmlNode method returns an XmlNode, such as a child, is this 
> generated on-the-fly or is it the actual component of the internal tree 
> structure?
Why internal? There is no internal or external tree, there is just tree 
of XmlNode objects.

> If the parent is moved in the tree, will the pointer remain 
> valid?
Sure.
-- 
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
0
Oleg
2/4/2004 10:53:40 AM
Reply:

Similar Artilces:

XmlNode
When an XmlNode method returns an XmlNode, such as a child, is this generated on-the-fly or is it the actual component of the internal tree structure? If the parent is moved in the tree, will the pointer remain valid? I have looked at as much of the structure as I can using .NET Reflector and I think it will, but I want to be sure. I 'm planning to add XmlNodes to the Tag property of TreeNodes in a TreeView to be able to persist changes back to the document and I would like to know if this will take up any more memory than when they are not linked in this way, or if it is better to...

xmlNode.InnerText vs. xmlNode.Value
I've loaded the following xml into an XMLDocument object: <?xml version="1.0" ?> - <Preferences> <Institution>Argh</Institution> <Speaker>Chigier, Ben (1234)</Speaker> <Worktype>Addendum</Worktype> <speakerCode>1234</speakerCode> </Preferences> I then try to retrieve the value of the Institution node as follows: string s = myxmldoc.SelectSingleNode("/Preferences/Institution").Value; However, s is null after the call. But if I change the call to the following, s is what I'd expect: "A...

How to get the XML path of an XmlNode?
How can I get the full XML path (as string) of a specific XmlNode ? -- Thanks Sharon Sharon wrote: > How can I get the full XML path (as string) of a specific XmlNode ? What is "the full XML Path" of a node, do you have any definition for that? Some XML editors can assist you constructing or maybe even generating an XPath expression. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ Lets say I have the following XML file: <?xml version="1.0" encoding="utf.8"?> <System Name = "System"> <Parameters> <T1&...

XmlSerialization to XmlNode
I have a schema that I load into classes that mirror the schema using the XmlSerialization. The schema contains an xsd:Any that I load into 'Extra' as follows: [XmlElement(ElementName="Extra")] public XmlNode Extra { get { return extra;} set { extra = value;}} However, if I have: <Something> <Extra> <a>something</a> <b>another thing</b> </Extra> </Something> I would expect Extra to contain an XmlNode of : <Extra> <a>something</a> <b>another thing</b> <...

Problem with XmlNode.ChildNodes across different machines
I'm having the darndest XML config file problem that I really need help with. I'm supporting a .NET 1.1 desktop application with its own config file, and I implement IConfigurationSectionHandler so I can have a custom config section in my config file. The IConfigurationSectionHandler.Create method just returns the 'section' XmlNode back to the consumer. The config file looks kind of like this: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="MyConfigSettings" type="MyAssembl...

how to transform escaped xml contents in xmlnode
Hi, I have an XML document, created from ADO DataSet, which contains XML data in some nodes shown below: <NewDataSet> <Table> <field_name>My Selection</field_name> <field_type>dropdown</field_type> <field_choice_text> &lt;Choices&gt;&lt;Choice choice_text=\"xxx\" /&gt;&lt;Choice choice_text=\"yyy\" /&gt;&lt;Choice choice_text=\"zzz\" /&gt;&lt;/Choices&gt; </field_choice_text> <field_answer> xxx </field_answer> </Table> </NewDataSet> How can I get ...

What is the difference between XmlNode and XmlElement?
What is the difference between XmlNode and XmlElement? I'm trying to implement the code at http://www.devx.com/dotnet/Article/11616/0/page/3 in C# and I'm getting an error at this line: this.appSettingsElement = this.xml.SelectSingleNode("//configuration/appSettings"); Error: Cannot implicitly convert type 'System.Xml.XmlNode' to 'System.Xml.XmlElement' Thanks. Pluto wrote: > What is the difference between XmlNode and XmlElement? The same as between fruit and apple. XmlElement is particular type of XmlNode. > this.appSettingsElement = > this....

xmlnode question
Hello, I'm new to xml and I have a question: I try to do the following Dim doc As New XmlDocument doc.LoadXml("<Request><Root><Requestor name='' /><FlowData flowstatus='' /><Products><productdate productid='' /></Products></Root></Request>") Dim node As XmlNode = doc.SelectSingleNode("Request/Root/Requestor/@name") node.Value = "TestValue" Dim node3 As XmlNode = doc.SelectSingleNode("Request/Root/FlowData/@flowstatus") node3.Value = &q...

XmlNode.Value
Can anyone from M$ or anyone else for that matter explain to me the reasoning behind the intended usage for this property? I was quite surprised to find that this property may be null depending on the XmlNodeType. If one imagines a scenario where some hapless programmer adds a new node to an XML-document, e.g. childNode = doc.CreateNode (XmlNodeType.Element, "foo", ""); and then decides to set the *value* (the "string" between <nodename> and </nodename>) of this node, one could easily imagine that our programmer would look for a method or property ca...

XmlNode and XPath
Hi All, I noticed that XmlNode and XpathNavigator are quite similiar. XmlNode seems to navigate over an XML Doc and so does XPathNav so when do I use XPathNavigator instead of XmlNode? Thanks, JJ JJ wrote: > I noticed that XmlNode and XpathNavigator are quite > similiar. XmlNode seems to navigate over an XML Doc and > so does XPathNav so when do I use XPathNavigator instead > of XmlNode? XPathNavigator is unified XPath selection facility. It allows navigate over any XPathNavigable stores, including XmlDocument. In fact SelectNode method's using XPathNavigato...

XmlNode.HasChildNodes
I have the following issue. I'm trying to read to following XML doc. <Main> <Submain> <SubField1/> <SubField2/> </Submain> <Field1/> <Field2>AnyTextValue</Field2> </Main> I loop using foreach XmlNode and testing the HasChildNodes property. When I get to the <Submain> tag the HasChildNodes property is True When I get to the <Field1/> tag the HasChildNodes property is False so far it's clear. Then... When I get to the <Field2> tag the HasChildNodes property is True???!!! Is it correct that the ...

With an XmlNode from a NodeList Can you tell where you are in the original XmlDocument
This problem was raised in another post Assuming we have an XmlDocument (xDoc) that has a node (<dickster>) randomly dispersed throughout the hierarchy. eg <root> <A> <B> <C> <dickster>1</dickster> </C> </B> </A> <D> <dickster>2</dickster> </D> <E> <F> <dickster>3</dickster> <dickster>4</dickster> </F> </E> <dickster>5</dickster> </root> We use SelectNodes to get an XmlNodeList that mathce...

XmlDocument and XmlNode
Hi, I've loaded an XmlDocument from a file XML: this file has many similar XmlNode and it is difficult to select them by using SelectSingleNode of the object XmlDocument. I've this question: is it possible to identify each XmlNode of the XmlDocument by using an inner key or something like that ? I precise that I 'm not allowed to change the file XML, therefore I can't add any key element or attribute in each node. Thank in advance Siu wrote: > I've loaded an XmlDocument from a file XML: this file has many similar > XmlNode and it is difficult to select the...

Deserialize an XmlNode, HOW?
Lets say I have an XmlNode created by: Dim cs As XmlSerializer = New XmlSerializer(GetType(String)) Dim cms As MemoryStream = New MemoryStream cs.Serialize(cms, "This is a test") cms.Position = 0 Dim cd As XmlDocument = New XmlDocument cd.Load(cms) Dim contents As XmlNode = ImportNode(cd.DocumentElement, True) how to I deserialize this node again...I've tried something like: Dim cs As XmlSerializer = New XmlSerializer(GetType(String)) Dim ms As MemoryStream = New MemoryStream Dim xw As XmlWriter = New XmlTextWriter(ms, Nothing) c.WriteContentTo(xw) xw.Flush() ms.Position = ...

CDATA and XmlNode
Hello, I have the following code: // Read the XML document from the hard-drive. XmlDocument doc = new XmlDocument(); doc.Load("doc.xml"); // Create the document's root. XmlElement root = doc.DocumentElement; // Filter the node we want. XmlNodeList nodes; nodes = root.SelectNodes("/Pages/Page[@Filename='" + id + "']"); XmlNode node = nodes[0]; // Retrieve data from the node m_Filename = id; m_Caption = node["Caption"].InnerText; m_Conten...

Apparent documentation contradiction for XmlNode.SelectSingleNode(
I just noticed something confusing the MSDN documentation for the XmlNode.SelectSingleNode() function here http://msdn2.microsoft.com/en-us/library/fb63z0tw.aspx It says, under the "Return Value" section that "The XmlNode should not be expected to be connected "live" to the XML document." but in the sample code modifies the node returned from the function and then prints the entire document. Did I mis-interpret the description of the return value or is the sample wrong? I've done this before and it's always worked AFAIK. SailBoffin wrote: &g...

Add XmlNode
Here I have the definition of an XmlNode which is a property (PayPreference) on my Customer class containing an enum describing how the customer will pay. <PayPerference xsi:type="a4:Customer+CustomerPayOptions" xmlns:a4="http://schemas.microsoft.com/clr/nsassem/OsfDomain.Resources.Stage/OsfDomain%2C%20Version%3D1.0.0.1%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">cash</PayPerference> I now want to add this XmlNode to a different Xml file where the Customer class has not defined a PayPreference property. I get as far as locating the parent XmlNode ...

To read the last xmlNode immediately
Hello I have created a xml doc Dim xmlDoc As New XmlDocument xmlDoc.Load(ConfigurationSettings.AppSettings("RegistrazioneErroriXML")) The file.xml: <?xml version="1.0" standalone="yes" ?> - <NewDataSet> - <Eccezione> <ID>1</ID> <Utente>INFORLUAR</Utente> <Messaggio>Nuovo eccezione</Messaggio> </Eccezione> - <Eccezione> <ID>2</ID> <Utente>INFORLUAR</Utente> <Messaggio>Nuova eccezione catturata</Messaggio> </Eccezione> - <Eccezione> ...

XmlValidating Reader and XmlNodes
Is there a way to get the current XmlNode from the reader while in the validation event handler? What I'd like to do is display the error message along with the name of its parent node. In my XML format, there are parent nodes named differently with some of the same names for child nodes, so when I get an error message that references the 'LOGICALPOCKET' node that could be under more than one different parent node. I need to be able to tell the user which parent node it's under. Thanks, Todd Todd Bright wrote: > Is there a way to get the current XmlNode from t...

Converting an object into an XmlNode
Hi, Is there a clean way to build up an XML Node from an object? What I am presently doing to create the node is: 1. Create a StringWriter and then use XmlSerializer to serialize the object into that StringWriter. 2. Create a new XmlDocument called tempDoc and call tempDoc.LoadXml(stringWriter.ToString()) 3. Create an XmlNode by calling myDoc.ImportNode (tempDoc.LastChild, true) Then I call AppendChild() to add this new node into the correct position in myDoc. Is there a cleaner way to do this? For example, is there an XmlNodeWriter or equivalent? Thanks Hari Hari Menon wrote: >...

XmlNode.ChildNodes Bug????
Hi, I just tried to replace a single XmlNode with several ChildNodes. When doing this with the following code i found out that if you get the ChildNodes with 'ChildNodes' - property the nodes get removed. Is this possibly a Framework Bug?? foreach( XmlNode node in oldNode.ChildNodes ) { newNode.AppendChild( node ); } parent.ReplaceChild( newNode, oldNode ); After doing several Tests is tried it the following way and it worked fine. [code:1:f2d0f1e03d] for( int i = 0; i < oldNode.ChildNodes.Count; i++ ) { XmlNode node = oldNode.ChildNodes[ i ]; newNode.AppendC...

XmlNode Enum Test
Is there a way to test if an XmlNode represents an enum? Paul wrote: > Is there a way to test if an XmlNode represents an enum? I don't understand the question, XmlNode is an abstract base class for several derived classes like XmlDocument, XmlDocumentFragment, XmlAttribute and others. How do you think does an XmlDocument or XmlDocumentFragment for instance look that "represents an enum"? -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ Could yuo be more specific? To check if an string/int is defined in a enum, use Enum.IsDefined method. Thi - http:...

xmlnode as custom object
Greetings, I have seen this question posted a few times, but the answers have not helped me. I have used the program xsd.exe to generate several c# classes from a client provided xsd template. I now wish take a sizeable amount of data and create an xml file based on these classes. My intent is to use xmldocument to build up the xml and then stream it to a file. My problem is I cannot use my new classes as nodes since they are not derived from nodes and they cannot be cast as such. What would be the best way to approach this? Cheers, Ian Williamson Use the classes you created...

XmlNode and read as BinHex
Hi, I'm processing a document using XmlDocument and I have an XmlNode whose value is stored as a binhex encoded string... How can I get this string converted back to a byte[]... XmlConvert has some internal methods but is there no public .net framework classes or methods that will do this... Thanks Donal Hi Donal, You can use a static method XmlConvert.FromBinHexString to convert the BinHex encoded string to byte[]. You can check the following link for more information on this method. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/ frlrfsystem...

How to tell if XmlNode is part of document tree
I have a container of XmlNodes. Some of them have been removed from the document, some haven't. Is there an easy way to tell which are which? I suppose bool IsPartOfTree(XmlNode node) { while (node.ParentNode != null) { node = ParentNode; } return node == node.OwnerDocument; } would work, but it doesn't seem elegant. martinfrompi@yahoo.co.uk wrote: > bool IsPartOfTree(XmlNode node) > { > while (node.ParentNode != null) { node = ParentNode; } Should be while (node.ParentNode != null) { node = node.ParentNode; } I guess. ...