I have a big xml structure. I am interested in certain xml structure like below. I need to extract img tags only and the value of the src attribute if they are inside coral-card. I was trying to use regex to get coral-card enclosing tags with a regex and then use regex with the coral-card tags to get to the img tag and the content.
var regex = /<coral\-card ((.|[\r\n])*?)<\/coral\-card>/g;
<coral-card variant="condensed" data-timeline="true" stacked>
<coral-card variant="semi-condensed" data-timeline="true" stacked>
DOMParser and xpath are very easy to use for parsing xml. You can do something like:
const DOMParser = require('xmldom').DOMParser; const xpath = require('xpath'); let parser = new DOMParser(); let doc = parser.parseFromString(<your xml>); let document = doc.documentElement; let coralCards = xpath.select('<path>/coral-card', document);
See xpath docs for all of the ways you can extract nodes out of an xml blob.