我面臨的問題是我無法使用 Dart 中 xml 包中的 getElement 函式。我正確決議了 xml 檔案,我可以顯示整個檔案的字串,但是當我使用 getElement 時,函式回傳 null。
這是xml檔案
<?xml version="1.0" encoding="UTF-8"?>
<qti-assessment-item
xmlns="http://www.imsglobal.org/xsd/qti/imsqtiasi_v3p0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqtiasi_v3p0
https://purl.imsglobal.org/spec/qti/v3p0/schema/xsd/imsqti_asiv3p0_v1p0.xsd"
identifier="firstexample"
time-dependent="false"
xml:lang="en-US">
<qti-response-declaration base-type="identifier" cardinality="single" identifier="RESPONSE">
<qti-correct-response>
<qti-value>A</qti-value>
</qti-correct-response>
</qti-response-declaration>
<qti-outcome-declaration base-type="float" cardinality="single" identifier="SCORE">
<qti-default-value>
<qti-value>A</qti-value>
</qti-default-value>
</qti-outcome-declaration>
<qti-item-body>
<p>Of the following hormones, which is produced by the adrenal glands?</p>
<qti-choice-interaction max-choices="1" min-choices="1"
response-identifier="RESPONSE">
<qti-simple-choice identifier="A">Epinephrine</qti-simple-choice>
<qti-simple-choice identifier="B">Glucagon</qti-simple-choice>
<qti-simple-choice identifier="C">Insulin</qti-simple-choice>
<qti-simple-choice identifier="D">Oxytocin</qti-simple-choice>
</qti-choice-interaction>
</qti-item-body>
<qti-response-processing
template="https://purl.imsglobal.org/spec/qti/v3p0/rptemplates/match_correct"/>
</qti-assessment-item>
加載xml檔案的函式
Future<String> loadString(BuildContext context, String path) async {
return await DefaultAssetBundle.of(context).loadString(path);
}
嘗試獲取檔案的一個元素
XmlDocument? xmlDocument;
loadString(context, "assets/qti3/items/choice-single-cardinality.xml").then(
(value) {
xmlDocument = XmlDocument.from(value);
XmlElement? response =
xmlDocument!.getElement("qti-response-declaration");
},
);
我嘗試了其他沒有連字符的 xml 檔案和 xml 標記,但到目前為止沒有任何效果..
uj5u.com熱心網友回復:
getElement只回傳一個直接子元素,使用findAllElements查找樹深處的元素。有關這些和許多其他訪問器的描述,請參閱有關遍歷和查詢的教程。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/454743.html
