Adding Xelement as a Sibling of Xelement without a Parent - vb.net

I'm trying figure out if this is possible. Basically, I need to create an XElement and then add one or more siblings to that XElement, but without a parent. I'll add that list of XElements to a Parent later, but need some flexibility in building this and other lists of XElements before doing so. Is this possible?
So I would have something like:
Public items As XElement = <ItemA>Something</ItemA>
And then I need to add an element so that the result looks like:
<ItemA>Something</ItemA>
<ItemB>Something Else</ItemB>
That result is what I need to pass around as a single object. I've messed arounnd with IEnumerable(Of XElement), but there is no .Add.
Any thoughts?

then add one or more siblings to that XElement, but without a parent
That's not going to work, elements are only siblings because they share a Parent ...
You'll have to use a temporary parent that you later change or replace.
You can of course use any collection (List<XElement>) to keep a list that you later turn into a list of siblings. Not clear what your problem with that is.

Related

is it not able to delete Child node directly?

I am a very beginner and code is like this:
function itemDone(e) {
var target, elParent, elGrandparent;
target = getTarget(e);
elParent = target.parentNode;
elGrandparent = target.parentNode.parentNode;
elGrandparent.removeChild(elParent);
is there any other way that I can delete the child element directly with any keyword rather than find parent and grandparent and then delete child element from parent.
thank you.
No, there is no way. You need to know the parent in order to remove the child. Unless you are dealing with double indirection which you would need pointers for and a different language.

Remove all items from NSTreeController

I would like to clear all items out of an NSTreeController that I added using Controller.AddObject. Is this possible? I presume it is possible to retrieve all the index paths, sort by depth in reverse and remove the items one by one, but I'm hoping for a way just to clear the data.
Simply replace the whole tree model by calling setContent: on your NSTreeController.
This removes everything but makes adding new elements impossible:
[treeController setContent:nil];
Prefer to replace it with an empty collection instead:
[treeController setContent:#[]];
Depending on your model, you might need to do additional set-up for the collection.

Check whether the given object is a list?

How can we check whether the given object is a list or other type
in velocity. In that list i have another list which i need to iterate again.
I also have another data in the parent list which i want to print while iterating parent list. But the problem is the child list object also get printing with actual data. So i want to print the data by checking whether its list or not. Any help is much appreciated.
Before you get any remarks on using too much logic in templates, try this reflection based approach :
velocity (test instanceof)

Get the Type of an object's children in silktest

Assume i have an object and it has lots of children.May i know how i can find their types?
I first used getChildren() to get the children and then used typeof() for each child.
Typeof always returns
Window.
I would like to find if they are DomTextField or DomLink etc and not Window.
Thanks
The easiest way is to use yourParent.FindAll(/DomTextField), this will give you all direct children, if you want to include all descendants, use yourParent.FindAll(//DomTextField).

Using Criteria to get only base types

I'm looking for way in Fluent NHibernate to get a list of all object of type PARENT
using criteria.
I have a father object and a derived child.
The father contains a list of childs.
The problem is that when I use:
ICriteria crit = session.CreateCriteria(typeof(Parent))
IList<Parent> myRes = crit.List<Parnet>()
NH return back the list of both parent elements and the derived children elements, which is "right" b/c that is what I've asked, but that is not what I need.
(the children elements should be only inside the father object, but since they are of type parent as well - since they derived from it... NH brings them as well using this method.)
How can I get the list of all my "father" elements without the derived children ?
This is from the first answer (#Stefan Steinegger's)
session
.CreateQuery("from Parent where Parent.class == :class")
.AddType(typeof(Parent));
It looks like I need something like that - but it doesn't work in Fluent NHibernate.
Thanks,
Dani
the question actually is: how do you determine if a Parent is a root parent? there are various approaches:
You keep your model and define: a root is a Parent that is not inherited and is not included in any other Parent.
The part "is not inherited" might be easy to determine, but is actually a poor definition. When using inheritance, you should actually not care if an object you get as a certain type is actually inherited or not, this is the nature of inheritance.
The part "is not included in any other Parent" is hard to find out in an efficient way.
You set a reference to an objects parent. A root is a Parent where its parent references null.
You derive your Root from a common Base class. A Child is not a Root anymore, and a Root is a Root.
I suggest to take the last option.
BTW: you can filter for the exact type, but only using HQL.
session
.CreateQuery("from Parent where Parent.class == :class")
.AddType(typeof(Parent));