Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlText Constructor not recognised? #19

Closed
lubi888 opened this issue Aug 5, 2016 · 6 comments
Closed

XmlText Constructor not recognised? #19

lubi888 opened this issue Aug 5, 2016 · 6 comments

Comments

@lubi888
Copy link

lubi888 commented Aug 5, 2016

Trying to follow the most basic code from the docs and what's wrong with this code that's it's producing error?

import 'package:xml/xml.dart' as xml;

void main(){
var bookshelfXml = '''<?xml version="1.0"?>
    <bookshelf>
      <book>
        <title lang="english">Growing a Language</title>
        <price>29.99</price>
      </book>
      <book>
        <title lang="english">Learning XML</title>
        <price>39.95</price>
      </book>
      <price>132.00</price>
    </bookshelf>''';
var document = xml.parse(bookshelfXml);

print(document.toString());
print('-------------------');
var textual = document.descendants
    .where((node) => node is XmlText && !node.text.trim().isEmpty)
    .join('\n');
print(textual);

//the following works fine.
// var titles = document.findAllElements('title');
// titles
//     .map((node) => node.text)
//     .forEach(print);
}

the error produced is;

Unhandled exception:
'file:///home/xxxxx/dart/xmlXSLT/bookxml.dart': malformed type: line 21 pos 30: type 'XmlText' is not loaded
    .where((node) => node is XmlText && !node.text.trim().isEmpty)
                             ^


#0      _TypeError._throwNew (dart:core-patch/errors_patch.dart:65)
#1      main.<anonymous closure> (file:///home/iveagh/dart/xmlXSLT/bookxml.dart:21:30)
#2      WhereIterator.moveNext (dart:_internal/iterable.dart:439)
#3      Iterable.join (dart:core/iterable.dart:303)
#4      main (file:///home/iveagh/dart/xmlXSLT/bookxml.dart:22:6)
#5      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:261)
#6      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)

@renggli
Copy link
Owner

renggli commented Aug 5, 2016

Oups, that's a bug in the docs. The package is imported as xml, so you need to prefix all references with xml., i.e. xml.XmlText. I'll update the docs in a second.

@lubi888
Copy link
Author

lubi888 commented Aug 5, 2016

wow that was quick!
thanks so much, renggli

@lubi888 lubi888 closed this as completed Aug 5, 2016
@renggli
Copy link
Owner

renggli commented Aug 5, 2016

Fixed in 3b3e355.

Please let me know if you encounter other problems!

@lubi888
Copy link
Author

lubi888 commented Aug 5, 2016

Hi renggli,
no other probs yet but if i wanted to ask you simple questions about Dart, Xml and Xslt and using and Xml database where would be the best place to do that?

would it be stackoverflow, dartlang.slack (or perhaps some other slack) or just gmail||G+ you?

if you don't have time that's ok.....

@renggli
Copy link
Owner

renggli commented Aug 5, 2016

Preferably ask on StackOverflow, I think you can reach the widest community there.

@lubi888
Copy link
Author

lubi888 commented Aug 5, 2016

thanks, renggli. later....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants