lubi lubi - 6 months ago 30
Dart Question

Could XmlBuilder.processing accept more arguments?

Would it be possible to add more info when building and xml doc with dart-xml?

Both of the following work fine for building xml, xslt.

builder.processing('xml', 'version="1.0"');
builder.processing('xml-stylesheet', 'type="application/xml"');

With xml I'd like to add UTF instructions to help internationalization.

builder.processing('xml', 'version="1.0"', 'encoding="UTF-8"');
//gives error '2 positional arguments expected, but 3 found'

Trying to link to XSLT would be helpful.

builder.processing('xml-stylesheet', 'type="application/xml"', href="hieroglyph.xsl");
//gives 2 errors; '2 positional arguments expected, but 3 found'
//'Undefined name 'href''

I think this is is set within dart-xml/lib/xml/grammar.dart and the processing() method.

processing() => string(OPEN_PROCESSING)
.map((each) => createProcessing(each[1], each[2]));
qualified() => ref(nameToken).map(createQualified);

Normal Xml elements can have 0,1 or many args so how would I enable processing() to do this? Is it a matter of changing a list to include more than 2 args or would it be more complicated and entail adding other definitions like 'href' for xslt or others for xsd?


I believe, dart-xml parses processing instructions as described in the standard. This means the parser simply splits everything between <? and ?> into a target and a data string.

Thus, the builder expects two strings as argument as well. You can simply write:

 builder.processing('xml', 'version="1.0" encoding="UTF-8"');
 builder.processing('xml-stylesheet', 'type="application/xml" href="hieroglyph.xsl"');

Probably it would be a good idea to add a method to the builder to simplify the creation of such XML declarations. Feel free file an issue.