Function readMediaSubtypeXML
Read MIME type from xml formatted data with mime-type root element as defined by spec.
Returns
MimeType
parsed from xml definition.
Throws
XMLMimeException
on format error.
See Also
Example
auto xmlData = `<?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="text/markdown">
<!--Created automatically by update-mime-database. DO NOT EDIT!-->
<comment>Markdown document</comment>
<comment xml:lang="ru">документ Markdown</comment>
<sub-class-of type="text/plain"/>
<x-unknown>Just for a test</x-unknown>
<glob pattern="*.md"/>
<glob pattern="*.mkd" weight="40"/>
<glob pattern="*.markdown" case-sensitive="true"/>
<alias type="text/x-markdown"/>
</mime-type>`;
auto mimeType = readMediaSubtypeXML(xmlData);
assert(mimeType .name == "text/markdown");
assert(mimeType .displayName == "Markdown document");
assert(mimeType .aliases == ["text/x-markdown"]);
assert(mimeType .parents == ["text/plain"]);
assert(mimeType .globs == [MimeGlob("*.md"), MimeGlob("*.mkd", 40), MimeGlob("*.markdown", defaultGlobWeight, true)]);
import std .exception : assertThrown, assertNotThrown;
auto notXml = "not xml";
assertThrown!XMLMimeException(readMediaSubtypeXML(notXml));
auto invalidEmpty = `<?xml version="1.0" encoding="utf-8"?>`;
assertThrown!XMLMimeException(readMediaSubtypeXML(invalidEmpty));
auto notNumber = `<mime-type type="text/markdown">
<glob pattern="*.mkd" weight="not_a_number"/>
</mime-type>`;
assertThrown!XMLMimeException(readMediaSubtypeXML(notNumber));
auto validEmpty = `<mime-type type="text/markdown"></mime-type>`;
assertNotThrown(readMediaSubtypeXML(validEmpty));
auto missingName = `<mime-type></mime-type>`;
assertThrown(readMediaSubtypeXML(missingName));
auto noPattern = `<mime-type type="text/markdown">
<glob pattern=""/></mime-type>`;
assertThrown!XMLMimeException(readMediaSubtypeXML(noPattern));