lodo1995 / experimental.xml

A replacement of Phobos std.xml
https://lodo1995.github.io/experimental.xml
Boost Software License 1.0
20 stars 8 forks source link

Example won't work #33

Closed anton-dutov closed 8 years ago

anton-dutov commented 8 years ago

Taken from here https://lodo1995.github.io/experimental.xml/std/experimental/xml.html

Code:

import std.stdio;

import std.experimental.xml;

void main()
{
    string input = q"{
<?xml version = "1.0"?>
<books>
    <book ISBN = "078-5342635362">
        <title>The D Programming Language</title>
        <author>A. Alexandrescu</author>
    </book>
    <book ISBN = "978-1515074601">
        <title>Programming in D</title>
        <author>Ali Çehreli</author>
    </book>
    <book ISBN = "978-0201704310">
        <title>Modern C++ Design</title>
        <author>A. Alexandrescu</author>
    </book>
</books>
    }";

    // the following steps are all configurable
    auto domBuilder =
         chooseLexer!input  // instantiate the best lexer based on the type of input
        .parser             // instantiate a parser on top of the lexer
        .cursor             // instantiate a cursor on top of the parser
        .domBuilder;        // and finally the DOM builder on top of the cursor

    // the source is forwarded down the parsing chain and everything is initialized
    domBuilder.setSource(input);

    // recursively build the entire DOM tree
    domBuilder.buildRecursive;
    auto dom = domBuilder.getDocument;

    // find and substitute all matching authors
    foreach (author; dom.getElementsByTagName("author"))
        if (author.textContent == "A. Alexandrescu")
            author.textContent = "Andrei Alexandrescu";

    // write it out to "catalogue.xml"
    auto file = File("catalogue.xml", "w");
    file.lockingTextWriter
        .writerFor!string   // instatiates an xml writer on top of an output range
        .writeDOM(dom);     // write the document with all of its children
}

Output:

Performing "debug" build using dmd for x86_64.
std-experimental-xml 0.1.2: target for configuration "library" is up to date.
t ~master: building configuration "application"...
source/app.d(28,9): Error: no property 'parser' for type 'SliceLexer!(string, void function() pure nothrow @nogc @safe, shared(GCAllocator), cast(Flag)true)'
source/app.d(47,9): Error: template std.experimental.xml.writer.writerFor cannot deduce function from argument types !(string)(LockingTextWriter), candidates are:
.../writer.d(497,6):        std.experimental.xml.writer.writerFor(StringType, alias PrettyPrinter = PrettyPrinters.Indenter, OutRange)(ref OutRange outRange)
.../writer.d(504,6):        std.experimental.xml.writer.writerFor(StringType, OutRange, PrettyPrinter)(ref OutRange outRange, auto ref PrettyPrinter printer)
anton-dutov commented 8 years ago

And that working:

auto domBuilder =
     chooseParser!input
    .cursor
    .domBuilder;
lodo1995 commented 8 years ago

I'm currently traveling. I'll have a look tomorrow. In the mean time, can you checkout the master branch? It appears that you are using the latest release, while the online documentation is automatically built from master. If that's the case, changing parser to parse may solve the issue (it has been a recent rename).

anton-dutov commented 8 years ago

I also tried ~master branch, but got another error with incompatible parameters.

anton-dutov commented 8 years ago

@lodo1995 ping

lodo1995 commented 8 years ago

I know. I'm just being very short on time. I hope to upload something soon.

lodo1995 commented 8 years ago

The examples should now work correctly. Feel free to reopen if I missed something.