doc = xmlread(filename)
[doc, parser] = xmlread(filename)
doc = xmlread(filename, name, value)
| Parameter | Description |
|---|---|
| filename | a string: path to the XML file. |
| name, value | optional pairs: 'AllowDoctype' or 'XMLEngine'. |
| Parameter | Description |
|---|---|
| doc | a Nelson xmlDocument object. |
| parser | an empty placeholder kept for parser compatibility. |
xmlread parses an XML file and returns a Nelson xmlDocument object that can be passed to xmlwrite or xslt.
The object also provides a small DOM-style access layer: getDocumentElement, getElementsByTagName, getTagName, getNodeName, getTextContent, getAttribute, hasAttribute, getLength, and item.
The returned object is not a complete external DOM implementation. The optional second output is currently an empty parser placeholder.
xml_filename = [tempdir(), 'xmlread_books.xml'];
xml_text = ['<catalog>', ...
'<book id="b1"><title>Numerical Methods</title><year>2026</year></book>', ...
'<book id="b2"><title>Signal Processing</title><year>2025</year></book>', ...
'</catalog>'];
filewrite(xml_filename, xml_text);
doc = xmlread(xml_filename);
root = doc.getDocumentElement();
root_name = root.getTagName()
books = doc.getElementsByTagName('book');
count = books.getLength()
first_book = books.item(0);
book_id = first_book.getAttribute('id')
book_text = first_book.getTextContent()
xmlwrite(doc)
| Version | Description |
|---|---|
| 2.0.0 | initial version |