473,769 Members | 6,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with XmlNode.InsertA fter

Hi,
I am having major headaches with XmlNode.InsertA fter. This is the
format of my XML document

<?xml version="1.0" encoding="utf-8"?>
<Team name="Team">
<Players>
<Player>
<name> GK</name>
<age> 28 </age>
<position> GK</position>
</Player>
<Player>
<name> P1</name>
<age> 22 </age>
<position> GK</position>
</Player>
<Player>
<name> P2</name>
<age> 32 </age>
<position> D</position>
</Player>
<Player>
<name> P3</name>
<age> 27 </age>
<position> D</position>
</Player>
</Players>
<Staff>
<Manager>
<name> Manager </name>
</Manager>
<Assistant-Manager>
<name> Assistant Manager </name>
</Assistant-Manager>
<Physio>
<name> Physio </name>
</Physio>
</Staff>
</Team>

I can locate a node but when I try to do an insert after on that node
I get "The reference node is not a child of this node". This is the
code

XmlNode root2 = doc2.DocumentEl ement;

//Create a new Element.
XmlElement newPlayer = doc2.CreateElem ent ("Player");

//doc2.DocumentEl ement.FirstChil d.AppendChild (newPlayer); - this
works but I want to be able to control where exactly the new Player
goes
doc2.InsertAfte r (newPlayer, doc2.DocumentEl ement.FirstChil d);

// I have tried finding a Player Node and calling insertafter using
that node as a reference but that fails as well. I'd appreciate any
help.

Also If anyone knows where I can find the Syntax for XPathExpression s
please reply.

All the best,

JD
Nov 12 '05 #1
4 5887


The Kiddie wrote:

XmlNode root2 = doc2.DocumentEl ement;

//Create a new Element.
XmlElement newPlayer = doc2.CreateElem ent ("Player");

//doc2.DocumentEl ement.FirstChil d.AppendChild (newPlayer); - this
works but I want to be able to control where exactly the new Player
goes
doc2.InsertAfte r (newPlayer, doc2.DocumentEl ement.FirstChil d);


That should be
doc2.DocumentEl ement.InsertAft er(newPlayer,
doc2.DocumentEl ement.FirstChil d);

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Thanks for that but it doesn't solve my problem. Ha, I just figured it
out. Here is the code that will work

doc2.DocumentEl ement.FirstChil d.InsertAfter(n ewPlayer,
doc2.DocumentEl ement.FirstChil d.ChildNodes[6]);

i'm still not exactly sure about the relationship between the node that
comes before the ".insertaft er" and the reference node (2nd parameter).

Also can anyone tell me the difference between an XMLNode and an
XMLElement

Cheers,

JD

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3


John O Donovan wrote:

i'm still not exactly sure about the relationship between the node that
comes before the ".insertaft er" and the reference node (2nd parameter).


It has to be the parent node.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
"John O Donovan" <jo*********@my realbox.com> wrote in message news:u8******** ******@TK2MSFTN GP15.phx.gbl...
Also can anyone tell me the difference between an XMLNode and an
XMLElement


XmlElement inherits from the more abstract XmlNode base type. A document is
composed of a bunch of nodes, nodes can be contained in other nodes, and this
simple structure is what creates the hierarchical (tree-like) form of an XML doc.

Here's the skinny on Node from the source,

http://www.w3.org/TR/2004/REC-DOM-Le...#ID-1950641247

you'll notice that as it's defined by the W3C, Node is an interface. This means
a node is never created directly. Instead, a specialized implementation of a Node
is what's created, and there's are several of these concrete nodes (comments,
processing instructions, CDATA sections, entity references, text, attributes,
etc.)

An element is a special kind of node, and it normally has a string representation
involving angle brackets, like this <name></name> or <name />. Elements can
contain attribute nodes, text nodes, other subordinate element nodes, comment
nodes, CDATA section nodes, entity references, processing instructions ...

The official definition is here,

http://www.w3.org/TR/2004/REC-DOM-Le...l#ID-745549614

In summary, everything is a node. Only tags are elements.
Derek Harmon
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3748
by: chris yoker | last post by:
hiya, I succesfully return a "nodeList" thru the "xmlDoc.SelectNodes" method. This nodeList is taken from a repetitive, uniform xml doc. I can successfully append a child node at the correct position using the following code: <code> <!--Node inserted into corrrect position in nodeList(0)-->
2
2907
by: Jesper Stocholm | last post by:
I use an XmlTextWriter to generate xml data. The declaration is: System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter sw = new System.IO.StringWriter(sb); XmlTextWriter w = new XmlTextWriter(sw); And I write to it using
3
1930
by: DR BILRO | last post by:
considering the following xml example <?xml version="1.0" encoding="ISO8859-1"?> <results> <interaction> <point> <auxf>6.812890</auxf> <auxh>0.000000</auxh> </point>
3
8119
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to run the class it gives an error that "System.Xml.XmlNode.XmlNode() is inaccessible due to its protection level". This error comes because XmlNode has not any public constructor. I found XmlNode has two constructor but both are private or friend...
5
2143
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to run the class it gives an error that "System.Xml.XmlNode.XmlNode() is inaccessible due to its protection level". This error comes because XmlNode has not any public constructor. I found XmlNode has two constructor but both are private or friend...
5
2166
by: Chua Wen Ching | last post by:
Hi, I read from this tutorial at codeproject Question A: http://www.codeproject.com/csharp/GsXPathTutorial.asp regarding xpath.. but i try to apply in my situation, and can't get it work...
7
2002
by: John Bowman | last post by:
Hi All, I'm fairly new to XML, so I presume I'm doing something obviously dense here, but here it goes. Below is an XML file that was extracted from a test Windows Installer .MSP (patch) file using the MsiExtractPatchXMLData() method and directly written to disk as a test. On the surface, it seems to me to be valid XML since IE can load & display it. <MsiPatch xmlns="http://www.microsoft.com/msi/patch_applicability.xsd"...
1
1321
by: PaulF | last post by:
I am trying to do add a repeating XmlNode into and existing XML document and have had some problems. The base XML: <Property> <Premises> <Endorsement> <ShortWording/> <Wording/>
3
1536
by: Joshua Stewart | last post by:
Hi, I am trying to characterise a problem I am seeing on our C#/C++ xml driven application. We have recently added some basic Spanish language support to our application, but it seems that there is an issue with certain locale settings. Under Regional and Language Options -Standards and Formats I would normally change the applications language by selecting Spanish (Mexico). It looks like the application ignores the Location field.
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.