Open wilzbach opened 6 years ago
From @talios on July 23, 2017 3:49
Solved with the following:
private auto getChildByTagName(T)(T parent, string name) {
foreach (child; parent.childNodes) {
if (child.nodeName == name) {
return child;
}
}
return null;
}
altho I see the entire library no longer works under the latest DMD release.
From @talios on July 7, 2017 22:19
Is there an easy(ish) way of finding an immediate child element by tag name?
getElementsByTagName
returns a node list of all matching tags, regardless of depth, I see theres achildNodes
property not really sure how to iterate it properly ( I tried extracting a loop to a function but can't for the life of me work out what type I should declare a node argument as ( D newbie, it looks like some template specialised type? ).Anyway, this is the function I have currently:
and this is my unittest:
The
getElementsByTagName
call forversion
is finding the/project/parent/version
element rather than the desired/project/version
( oh I wish for XPath here ).What would be the idiomatic D way of handling this?
As an aside, I found it interesting that I had to use
getElementsByTagName
and NOTgetElementsByTagNameNS
which I assumed I should do ( which I do in Java, and other XML processing libraries ) since the XML declares a top-level default namespace. Is that due to how the DOMBuilder is built?Copied from original issue: lodo1995/experimental.xml#43