I'm trying to extract extract data from a scientific journal (provided in JSON format) however one value of the JSON (key = abstract) is returned in a JATS-XML format, the standardized XML format for scientific research publications.
"abstract": "<jats:title>Summary</jats:title>\n
<jats:sec>\n <jats:title>Objective</jats:title>\n
<jats:p>To systematically evaluate all the evidence assessing variations in the depth of the curve of Spee (COS) according to the presence/absence of different dentoskeletal characteristics.</jats:p>\n
</jats:sec>\n <jats:sec>\n
<jats:title>Search methods and eligibility criteria</jats:title>\n
<jats:p>The eligibility criteria were outlined following the PECO framework, as follows: studies evaluating individuals with complete permanent dentition including second molars (P), which compared a group with a certain dentoskeletal variation (E) versus another group without the variation (C), regarding the depth of the COS (O). MEDLINE (via PubMed), Scopus, Web of Science, The Cochrane Library, LILACS and BBO (via Virtual Health Library), OpenGrey, and Google Scholar were searched up to September 2021 to identify eligible reports.</jats:p>\n
</jats:sec>\n <jats:sec>\n
<jats:title>Data collection and analysis</jats:title>\n
<jats:p>Duplicates were removed from all the records retrieved. The selection process and data collection were performed independently by two review members. The risk of bias was also assessed independently and in duplicate, using the guideline described by Fowkes and Fulton. Several meta-analyses (α = 0.05) were conducted to estimate the mean differences (MD) or standardized mean differences (SMD) in the depth of COS between individuals presenting or not certain dentoskeletal characteristics. The certainty of evidence was assessed using the GRADE tool.</jats:p>\n </jats:sec>\n
<jats:sec>\n <jats:title>Results</jats:title>\n
<jats:p>Thirty-five studies were selected for qualitative synthesis, and 29 of them for quantitative synthesis. All studies had methodological limitations that affected the risk of bias and increased the likelihood that results were due to chance. Syntheses showed that Class II malocclusion (SMD = 0.87; 95% CI: 0.61, 1.13; P &lt; 0.00001; six datasets including 260 subjects analysed), Class II division 1 (SMD = 1.09; 95% CI: 0.62, 1.56; P &lt; 0.00001; 14 datasets including 823 subjects analysed) and Class II division 2 (SMD = 2.65; 95% CI: 1.51, 3.79; P &lt; 0.00001; eight datasets including 476 subjects analysed) had deeper COS than Class I malocclusion. The skeletal Class II also presented higher COS values than skeletal Class I (SMD = 0.57; 95% CI: 0.02, 1.12; P = 0.04; four datasets including 299 subjects analysed). Individuals with Class III malocclusion had flatter COS than the subjects having Class I malocclusion (SMD = −0.57; 95% CI: −1.07, −0.08; P = 0.02; nine datasets including 505 individuals analysed). No difference was shown in the COS depth between skeletal Class III and Class I (P &gt; 0.05). Deep bite individuals had higher COS depth than those with normal overbite (MD = 0.61; 95% CI: 0.41, 0.82; P &lt; 0.00001; two datasets including 250 subjects analysed). In addition, hypodivergent individuals presented deeper COS than normodivergents (SMD = 0.62; 95% CI: 0.37, 0.86; P &lt; 0.00001; six datasets including 305 subjects analysed), and there was no significant difference in the COS depth between hyperdivergent and normodivergent individuals (P = 0.66). The certainty of evidence was rated as very low for all the syntheses.</jats:p>\n </jats:sec>\n <jats:sec>\n
<jats:title>Limitations</jats:title>\n <jats:p>All the quantitative syntheses included results from studies with methodological flaws. Therefore, they are potentially biased. Moreover, the evidence was also mainly affected in terms of the inconsistency of the results and the imprecision of the estimates.</jats:p>\n </jats:sec>\n
<jats:sec>\n <jats:title>Conclusions</jats:title>\n
<jats:p>Although an apparent influence of dentoskeletal Class II, Class III malocclusion, deep bite, and the hypodivergent skeletal pattern on the depth of the COS is suggested, it is not possible to make definitive conclusions on the matter due to the very low certainty of the evidence. Further high-quality research is necessary.</jats:p>\n </jats:sec>"
I have tried using the Dart XML package but without any luck.
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:deep_pick/deep_pick.dart';
import 'package:xml/xml.dart';
Future<void> main() async {
final response =
await http.get(Uri.parse( < api > ));
final json = jsonDecode(response.body);
final abstract = pick(json, 'abstract').asStringOrThrow();
final abstractParse = XmlDocument.parse(abstract);
print(XmlDocument.parse(abstract).toXmlString(pretty: true));
CodePudding user response:
For some reason your XML doesn't have an overall enclosing tag, but you can just add one.
void main() {
final cleanInput = input.replaceAll('\\n', '');
final enclosedInput = '<root>$cleanInput</root>';
final doc = XmlDocument.parse(enclosedInput);
print(doc.firstElementChild!.firstElementChild); // prints <jats:title>Summary</jats:title>
}
First, optionally, get rid of the \n
, with the replaceAll
- even though the parser doesn't actually seem to mind them.
Then insert your XML between any tag of your choice (for example <root>
), and parse that. The top element will now be that root tag you added and its first child will be the title
tag.
So, change to:
final abstract = pick(json, 'abstract').asStringOrThrow().replaceAll('\\n', '');
final abstractDocument = XmlDocument.parse('<root>$abstract</root>');