On Wednesday, 2 August 2017 at 00:39:24 UTC, Mike wrote:
Looking at your code though, I probably should have used Adam's dom.d too; std.xml was weird to say the least.

There's a couple functions in dom.d too that might have simplified this:

foreach(EnumsTop; Flds.getElementsByTagName("enumeratedValues")){
        foreach(Enums; EnumsTop.getElementsByTagName("enumeratedValue")){
                foreach(child; Enums.childNodes){
if(child.tagName=="description"){EnumV.description = child.innerText();} if(child.tagName=="name" ){EnumV.name = child.innerText();} if(child.tagName=="value" ){EnumV.value = child.innerText();}
                }


This pattern is used throughout, and it is pretty nice. Not saying it is wrong!

But that could prolly be written:

foreach(Enums; Flds.querySelectorAll("enumeratedValues > enumeratedValue")) { EnumV.description = Enum.optionSelector("description").innerText();
    EnumV.name  = Enum.optionSelector("name").innerText();
    EnumV.value  = Enum.optionSelector("value").innerText();
}




The various *selector functions do CSS selector syntax. querySelector/querySelectorAll returns the first/all matching element, or null if none. requireSelector returns the first matching, or throws exception if there is none. optionSelector returns a wrapper object that is never null so you can call its methods, but they return null if it was.

Meaning you don't have to explicitly check presence, the .innerText just returns the null string if the element wasn't there.


The idea of these is to make navigating xml like this a bit more convenient.

Reply via email to