# -*- mode: perl6 -*- use NativeCall; class XML::LibXML::Node is repr('CStruct') { sub xmlFreeNode(XML::LibXML::Node $doc) is native('libxml2') {*} submethod DESTROY { xmlFreeNode(self) } has Pointer $!_private; has int $.xmlElementType; has Str $.name; # etc etc, don't try to create this } class XML::LibXML::Document is repr('CPointer') { sub xmlFreeDoc(XML::LibXML::Document $doc) is native('libxml2') {*} submethod DESTROY { xmlFreeDoc(self) } sub xmlDocGetRootElement(XML::LibXML::Document $doc) returns XML::LibXML::Node is native('libxml2') {*} method rootElement() { return xmlDocGetRootElement(self); } } class XML::LibXML::Context is repr('CStruct') { sub xmlFreeParserCtxt(XML::LibXML::Context $ctxt) is native('libxml2') {*} submethod DESTROY { xmlFreeParserCtxt(self) } sub xmlParseDocument(XML::LibXML::Context $ctxt) is native('libxml2') {*} method parse() { xmlParseDocument(self) } has Pointer $!sax; # currently unused has Pointer $!userData; # useless? has XML::LibXML::Document $.myDoc; # etc etc, don't try to create this } class XML::LibXML { sub xmlCreateMemoryParserCtxt(Blob $docbuf, int $len) returns XML::LibXML::Context is native('libxml2') {*} method parse(Str $docstring) { my Blob $docbuf = $docstring.encode('utf8'); my $ctxt = xmlCreateMemoryParserCtxt( $docbuf, $docbuf.bytes, ); $ctxt.parse(); return $ctxt.myDoc; } }