#xml
22 messages · Page 1 of 1 (latest)
Can you share a little more about what you're trying to do? There are npm libraries for parsing xml, and you can use npm libraries in your convex functions.
I have an rss xml document saved to file storage
What are you trying to do that you need help with
If you're successfully saving the file to storage, you can use a library like this to parse in the browser or in a convex function: https://www.npmjs.com/package/fast-xml-parser
thanks
I am pretty new to typescript/javascript so I am never sure what libraries to use
ah, gotcha
I started working on it using DOMParser https://developer.mozilla.org/en-US/docs/Web/XML/Parsing_and_serializing_XML
If that's working, standards are the way to go
In a convex function or in the browser
In the browser, FileReader.readAsText() should work: https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsText
Hmm actually looks like Blob has a text() method that returns a promise, have you tried that?
DOMParser is not defined
tried using fast-xml-parser
and it also gives this error
const { XMLParser, XMLBuilder, XMLValidator} = require("fast-xml-parser");
handler: async (ctx, args) => {
const rss_blob = await ctx.storage.get(args.storageId);
if(rss_blob == null){
console.error("doc empty")
return
}
const rss_text: string = await rss_blob.toString()
const parser = new XMLParser();
let jObj = parser.parse(rss_text);
const builder = new XMLBuilder();
const xmlContent = builder.build(jObj);
},
});