Why doesn't a XML attribute have a "parent" in .NET? -


so, i'm writing simple function remove xml node xml document. easiest way achieve this, far can tell, to:

  1. get reference node removed (childnode)
  2. get reference node's parent using childnode.parentnode property (parentnode)
  3. call parentnode.removechild(childnode) method

now, works great if child node xmlelement, if child node xml attribute? according msdn documentation xmlnode.parentnode, property return nothing, because "[attributes] not have parents."

attributes have "parents," not? attribute must assigned xml element, xml element attribute's parent, in mind.

can clear misunderstanding, or clarify why .net framework not see attributes having parents?

you can use xmlattribute.ownerelement owner of attribute.

your procedure have modified this:

  1. get reference node removed (childnode).

  2. if type of node xmlattribute downcast type (attributenode) , reference node's parent using attributenode.ownerelement property (parentnode). if not go step 4.

  3. call parentnode.attributes.remove(attributenode) method. skip remaining steps.

  4. get reference node's parent using childnode.parentnode property (parentnode).

  5. call parentnode.removechild(childnode) method.

so have give attributes special treatment reflecting fact not part of parent-child hierarchy rather - well, attributes - of xml element.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -