How to implement a simple parser that does well-formedness checking on XML, such
ID: 3917595 • Letter: H
Question
How to implement a simple parser that does well-formedness checking on XML, such as the following:
<BackgroundCheck>
<CriminalHistory>
<HistoryCode>x</HistoryCode>
<HistoryCode>y</HistoryCode>
<HistoryCode>z</HistoryCode>
</CriminalHistory>
</BackgroundCheck>
Please note that using a a parser like Xerces is not acceptable. You can either describe the algorithm, write pseudo code or optionally implement the solution.
Explanation / Answer
Here is pseudo code for create simple parse parsar in xml. <html><body> <p id="history"></p> <script>
var text, parser, xmlDoc;
text ="<HistoryCode>x</tHistoryCode>" +
"<HistoryCode>y<HistoryCode>" +
"<HistoryCode>z</HistoryCode>" +
"</book></bookstore>";
parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");
document.getElementById("history").innerHTML =
xmlDoc.getElementsByTagName("Historycode")[0].childNodes[0].nodeValue;
</script>
</body>
</html>
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.