For Programmers: Free Programming Magazines  


Home > Archive > C# > March 2004 > override CreateElement - getting the name of the parentNode DURING parsing ????









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author override CreateElement - getting the name of the parentNode DURING parsing ????
JoostV

2004-03-28, 10:28 pm

Xref: kermit microsoft.public.dotnet.csharp.general:2356

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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com