digitalmars.D.learn - What's dxml DOMEntity(R) type ?
- John Xu (10/10) Jun 05 2023 The parseDOM returns a DOMEntity(R) type, how do I write a
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (15/25) Jun 05 2023 ```d
- John Xu (3/30) Jun 05 2023 Thanks, that's very helpful. D sometimes drives me crazy, screws
- Steven Schveighoffer (8/36) Jun 06 2023 In general, the easiset thing to do is use typeof, though it's not
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (6/31) Jun 06 2023 İt is one of the nicest features of d. I believe it should not be
- Steven Schveighoffer (6/18) Jun 06 2023 It should not affect compile times at all. If you are going to
The parseDOM returns a DOMEntity(R) type, how do I write a xmlRoot as global variable? I need its detailed type (auto / Variant doesn't work). import dxml.dom; ?? xmlRoot; int main() { string xml = readText("a.xml"); auto dom = parseDOM(xml); xmlRoot = dom.children[0]; }
Jun 05 2023
On Monday, 5 June 2023 at 10:01:01 UTC, John Xu wrote:The parseDOM returns a DOMEntity(R) type, how do I write a xmlRoot as global variable? I need its detailed type (auto / Variant doesn't work). import dxml.dom; ?? xmlRoot; int main() { string xml = readText("a.xml"); auto dom = parseDOM(xml); xmlRoot = dom.children[0]; }```d import dxml.dom; import std.stdio; DOMEntity!string xmlRoot; int main() { string xml = "<some></some>"; auto dom = parseDOM(xml); writeln(typeof(dom.children[0]).stringof); // yields "DOMEntity!string" xmlRoot = dom.children[0]; return 0; } ```
Jun 05 2023
On Monday, 5 June 2023 at 10:43:27 UTC, Ferhat Kurtulmuş wrote:On Monday, 5 June 2023 at 10:01:01 UTC, John Xu wrote:Thanks, that's very helpful. D sometimes drives me crazy, screws up my brain, :-)The parseDOM returns a DOMEntity(R) type, how do I write a xmlRoot as global variable? I need its detailed type (auto / Variant doesn't work). import dxml.dom; ?? xmlRoot; int main() { string xml = readText("a.xml"); auto dom = parseDOM(xml); xmlRoot = dom.children[0]; }```d import dxml.dom; import std.stdio; DOMEntity!string xmlRoot; int main() { string xml = "<some></some>"; auto dom = parseDOM(xml); writeln(typeof(dom.children[0]).stringof); // yields "DOMEntity!string" xmlRoot = dom.children[0]; return 0; } ```
Jun 05 2023
On 6/5/23 6:43 AM, Ferhat Kurtulmuş wrote:On Monday, 5 June 2023 at 10:01:01 UTC, John Xu wrote:In general, the easiset thing to do is use typeof, though it's not always pretty (and not always obvious how to write it). However, it's required for voldemort types. ```d typeof(parseDom("")) DomEntity; ``` -SteveThe parseDOM returns a DOMEntity(R) type, how do I write a xmlRoot as global variable? I need its detailed type (auto / Variant doesn't work). import dxml.dom; ?? xmlRoot; int main() { string xml = readText("a.xml"); auto dom = parseDOM(xml); xmlRoot = dom.children[0]; }```d import dxml.dom; import std.stdio; DOMEntity!string xmlRoot; int main() { string xml = "<some></some>"; auto dom = parseDOM(xml); writeln(typeof(dom.children[0]).stringof); // yields "DOMEntity!string" xmlRoot = dom.children[0]; return 0; } ```
Jun 06 2023
On Tuesday, 6 June 2023 at 14:16:37 UTC, Steven Schveighoffer wrote:On 6/5/23 6:43 AM, Ferhat Kurtulmuş wrote:İt is one of the nicest features of d. I believe it should not be used too often because it may cause longer compilation times, worse code reading, less comfort with d code scanners, editors etcetera.On Monday, 5 June 2023 at 10:01:01 UTC, John Xu wrote:In general, the easiset thing to do is use typeof, though it's not always pretty (and not always obvious how to write it). However, it's required for voldemort types. ```d typeof(parseDom("")) DomEntity; ``` -Steve[...]```d import dxml.dom; import std.stdio; DOMEntity!string xmlRoot; int main() { string xml = "<some></some>"; auto dom = parseDOM(xml); writeln(typeof(dom.children[0]).stringof); // yields "DOMEntity!string" xmlRoot = dom.children[0]; return 0; } ```
Jun 06 2023
On 6/6/23 12:15 PM, Ferhat Kurtulmuş wrote:On Tuesday, 6 June 2023 at 14:16:37 UTC, Steven Schveighoffer wrote:In general, the easiset thing to do is use typeof, though it's not always pretty (and not always obvious how to write it). However, it's required for voldemort types. ```d typeof(parseDom("")) DomEntity; ```İt is one of the nicest features of d. I believe it should not be used too often because it may cause longer compilation times, worse code reading, less comfort with d code scanners, editors etcetera.It should not affect compile times at all. If you are going to instantiate it that way, it will need to be compiled regardless. `typeof` is very low cost, as it's a direct call on the compiler internals. Something like `ReturnType!Foo` is different. -Steve
Jun 06 2023