I am trying to read the content of the XML file. Probably this is basic JS stuff, but I seem can't make it work.
I am using Chrome's experimental Native File System API to read folders in folder:
const opts = {type: 'open-directory'};
handle = await window.chooseFileSystemEntries(opts);
const entries = await handle.getEntries();
...
Then, later on in the code I am entering one of the folders from the main directory and trying to read the file in it. The file system strucure is like this:
Directory > subdirectory > file
and the second part of the code looks like this:
var subdirHandle = await handle.getDirectory(oneOfTheFolders);
var xmlFile = await subdirHandle.getFile('subject.xml');
xmlDoc = domParser.parseFromString(xmlFile, "text/xml");
parsedNumber = document.evaluate(myXpathFce('nodeInXML'), xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext();
if(parsedNumber.childNodes.length >0){
...
I believe the issue is here var xmlFile = await subdirHandle.getFile('subject.xml');
with the file reading. If I loaded the file straight from the Input and used FileReader()
, I was able to get the content and parse it, but with the 'directory' approach I am getting null (for the evaluated document) like this Uncaught (in promise) TypeError: Cannot read property 'childNodes' of null
Edit here is what I get in console for the xmlFile variable. I just need to get the content (XML in text format) from this