13 Replies
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
npm
fast-xml-parser
Validate XML, Parse XML, Build XML without C/C++ based libraries. Latest version: 4.3.6, last published: a month ago. Start using fast-xml-parser in your project by running
npm i fast-xml-parser
. There are 2383 other projects in the npm registry using 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
MDN Web Docs
Parsing and serializing XML - XML: Extensible Markup Language | MDN
At times, you may need to parse XML content and convert it into a DOM tree, or, conversely, serialize an existing DOM tree into XML. In this article, we'll look at the objects provided by the web platform to make the common tasks of serializing and parsing XML easy.
If that's working, standards are the way to go
the doc is type blob
how do I convert that to a string
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?just figure that out
all the promises are confusing coming from a java background
yeah fair
got it working?
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); }, }); NEVER MIND, not sure why I was getting that error, think I am making progress again
const builder = new XMLBuilder(); const xmlContent = builder.build(jObj); }, }); NEVER MIND, not sure why I was getting that error, think I am making progress again