xml data
<?xml version="1.0" encoding="UTF-8"?>
<Workflow>
<ID>Workflow-MKRU</ID>
<LocalCachePath>Z:\MAITest\Cache</LocalCachePath>
<SharedCachePath></SharedCachePath>
<Name>Test WF</Name>
<Desc>I'm testing shit</Desc>
<Components>
<Component>
<ID>ImageReader</ID>
<Type>ImageReaderComp</Type>
<Name>ReaderU08</Name>
<Desc></Desc>
<Properties>
<Property Name="Filepath" Type="String">D:\StandardImages\Lena.jpg</Property>
<Property Name="DataType" Type="enum">0</Property>
</Properties>
<InputPorts/>
<OutputPorts>
<Port>
<Name>Image</Name>
<Type>ImageTransport</Type>
<Transport>
<ID>ImageReaderCompJXRX-Image</ID>
<Type>ImageTransport</Type>
<Method>1</Method>
<Location>Z:\ImageReaderCompJXRX-Image</Location>
<Name></Name>
<Desc></Desc>
<SrcComponent>ImageReaderCompJXRX-Image</SrcComponent>
<DstComponents>
<ID>EdgeDetectorCompMWSL-Image</ID>
<ID>ImageDRACompGGWG-InputImage</ID>
</DstComponents>
</Transport>
</Port>
</OutputPorts>
</Component>
<Component>
<ID>ImageReaderComp</ID>
<Type>ImageReaderComp</Type>
<Name>ReaderU16</Name>
<Desc></Desc>
<Properties>
<Property Name="Filepath" Type="String">D:\Lena.jpg</Property>
<Property Name="DataType" Type="enum">1</Property>
</Properties>
<InputPorts/>
<OutputPorts>
<Port>
<Name>Image</Name>
<Type>ImageTransport</Type>
<Transport>
<ID>ImageReaderCompDDIU-Image</ID>
<Type>ImageTransport</Type>
<Method>1</Method>
<Location>Z:\ImageReaderCompDDIU-Image</Location>
<Name></Name>
<Desc></Desc>
<SrcComponent>ImageReaderCompDDIU-Image</SrcComponent>
<DstComponents>
<ID>ImageWriterCompMILV-Image</ID>
</DstComponents>
</Transport>
</Port>
</OutputPorts>
</Component>
</Components>
</Workflow>
code
files.forEach(function (file) {
var xmlfile = require('fs').readFileSync(directoryPath+file, 'utf8');
var parser = new xml2js.Parser();
parser.parseString(xmlfile,function (err, result) {
var jsonresponse= JSON.stringify(result)
var jsonparsed = JSON.parse(jsonresponse);
console.dir(jsonparsed);
console.dir(jsonresponse);
});
});
So, that's everything i have so far. I've tried a number of xml2js parsers i've gotten it to response two different types of json responses but i still don't know how to parse it out the way i need to in order to insert in my DB. I'm basically looking for the best way to insert select xml data into a mongoDB. Below is the current state of my XML data. Primary goal: I need to get the information for each component xml node into mongodb.
{ Workflow:
{ ID: [ 'Workflow-MKRU' ],
LocalCachePath: [ 'Z:\\MAITest\\Cache' ],
SharedCachePath: [ '' ],
Name: [ 'Test WF' ],
Desc: [ 'I\'m testing shit' ],
Components: [ [Object] ] } }
'{"Workflow":{"ID":["Workflow-MKRU"],"LocalCachePath":["Z:\\\\MAITest\\\\Cache"],"SharedCachePath":[""],"Name":["Test WF"],"Desc":["I\'m testing shit"],"Components":[{"Component":[{"ID":["ImageReader"],"Type":["ImageReaderComp"],"Name":["ReaderU08"],"Desc":[""],"Properties":[{"Property":[{"_":"D:\\\\StandardImages\\\\Lena.jpg","$":{"Name":"Filepath","Type":"String"}},{"_":"0","$":{"Name":"DataType","Type":"enum"}}]}],"InputPorts":[""],"OutputPorts":[{"Port":[{"Name":["Image"],"Type":["ImageTransport"],"Transport":[{"ID":["ImageReaderCompJXRX-Image"],"Type":["ImageTransport"],"Method":["1"],"Location":["Z:\\\\ImageReaderCompJXRX-Image"],"Name":[""],"Desc":[""],"SrcComponent":["ImageReaderCompJXRX-Image"],"DstComponents":[{"ID":["EdgeDetectorCompMWSL-Image","ImageDRACompGGWG-InputImage"]}]}]}]}]},{"ID":["ImageReaderComp"],"Type":["ImageReaderComp"],"Name":["ReaderU16"],"Desc":[""],"Properties":[{"Property":[{"_":"D:\\\\Lena.jpg","$":{"Name":"Filepath","Type":"String"}},{"_":"1","$":{"Name":"DataType","Type":"enum"}}]}],"InputPorts":[""],"OutputPorts":[{"Port":[{"Name":["Image"],"Type":["ImageTransport"],"Transport":[{"ID":["ImageReaderCompDDIU-Image"],"Type":["ImageTransport"],"Method":["1"],"Location":["Z:\\\\ImageReaderCompDDIU-Image"],"Name":[""],"Desc":[""],"SrcComponent":["ImageReaderCompDDIU-Image"],"DstComponents":[{"ID":["ImageWriterCompMILV-Image"]}]}]}]}]}]}]}}'