#xml

22 messages · Page 1 of 1 (latest)

worthy orchid
#

wondering best way to process xml?

cold flume
#

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.

worthy orchid
#

I have an rss xml document saved to file storage

cold flume
#

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

worthy orchid
#

thanks

#

I am pretty new to typescript/javascript so I am never sure what libraries to use

cold flume
#

ah, gotcha

worthy orchid
cold flume
#

If that's working, standards are the way to go

worthy orchid
#

the doc is type blob

#

how do I convert that to a string

cold flume
#

In a convex function or in the browser

#

Hmm actually looks like Blob has a text() method that returns a promise, have you tried that?

worthy orchid
#

just figure that out

#

all the promises are confusing coming from a java background

cold flume
#

yeah fair

#

got it working?

worthy orchid
#

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);

},
});