473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

override CreateElement - getting the name of the parentNode ????

However, I am wondering if I can make the creation of my object depend
on the name of the parent node DURING parsing (or even the name of the
grandparent node)?? In other words, how can I do something like this:

class MyParser : XmlDocument
{
public override XmlElement CreateElement(string prefix, string
lname, ...)
{
//--> where can I get the ParentNode
// in the next line???????????????
if ( ParentNode.Name =="company" )
return new Employee(prefix, lname, nsuri, this)
else if (lname=="person")
return new Person(prefix, lname, nsuri, this);
else
return base.CreateElement(prefix, lname, nsuri);
}
}

{
...
MyParser parser = new MyParser()
parser.load( "C:\\test.xml" );
}

Does anybody have any ideas about how this can be solved??
Thanks.
Nov 12 '05 #1
1 1882
JoostV wrote:
However, I am wondering if I can make the creation of my object depend
on the name of the parent node DURING parsing (or even the name of the
grandparent node)?? In other words, how can I do something like this:

class MyParser : XmlDocument
{
public override XmlElement CreateElement(string prefix, string
lname, ...)
{
//--> where can I get the ParentNode
// in the next line???????????????


There is no "the ParentNode" of XmlDocument, instead each node a
ParentNode. CreateElement() method creates "dangling" node - it belongs
to the document, but doesn't apper in document tree. One has to append
or insert it to some other node.

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2

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

Similar topics

25
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to...
2
by: kie | last post by:
hello, when i create elements and want to assign events to them, i have realised that if the function assigned to that element has no parameters, then the parent node values can be attained. ...
2
by: Ivo | last post by:
I have this code to add a row to a table: var r=document.createElement('tr'); var c=document.createElement('td'); var cn=c.cloneNode(false); cn.className='tdname';...
3
by: Ben Hallert | last post by:
Hi there, I haven't done a lot of Javascript programming, so I'm not having great luck debugging something I put together, and I was hoping someone here could give it a quick lookover and maybe...
2
by: louissan | last post by:
Hi all, I have a slight problem with IE, when everything works with firefox. The goal is to _create_ boxes using the createElement method. And then making it draggable with the mouse. The code...
3
by: Arpan | last post by:
Using DOM, this is how I am appending data to an existing XML file which is named AppendData.xml (the root element of AppendData.xml is <ProductList>): <script runat="server"> Sub...
2
by: Yoavo | last post by:
Hi, I am trying to add an XmlElement to my XML file: XmlDocument aDoc = new Xml Document(); aDoc.Load("MyFile.xml"); XmlElement el = aDoc.CreateElement("Cim:Attr"); When I append this element...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
23
by: vunet | last post by:
It is recommended by some sources I found to create IFrames in IE using document.createElement('<iframe src="#">') instead of document.createElement('iframe'). Why and what browser versions to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.