Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何清理节点中的XML响应?_Node.js_Xml - Fatal编程技术网

Node.js 如何清理节点中的XML响应?

Node.js 如何清理节点中的XML响应?,node.js,xml,Node.js,Xml,我有一个从API中提取的XML文件,我想清理它并将其转换为JSON。我如何删除超级数据,如信封和页眉,但只保留产品数据 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <s:Header> <o

我有一个从API中提取的XML文件,我想清理它并将其转换为JSON。我如何删除超级数据,如信封和页眉,但只保留产品数据

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <u:Timestamp u:Id="_0">
            <u:Created>
                2019-10-17T13:53:13.751Z
            </u:Created>
            <u:Expires>
                2019-10-17T13:58:13.751Z
            </u:Expires>
        </u:Timestamp>
    </o:Security>
</s:Header>
<s:Body>
    <GetItemMastersResponse xmlns="http://www.xxxxx.com/xxxxx/2013/08">
        <GetItemMastersResult xmlns:a="http://schemas.datacontract.org/2004/07/xxxx.xxxx.xxx.Models.Inventory" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:ItemMaster>
                <a:Active>
                    false
                </a:Active>
                <a:Alias i:nil="true"/>
                <a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/xxxxxx.xxxx.xxxxxx.Models.Admin"/>
                <a:BarcodeFormat>
                    7
                </a:BarcodeFormat>
                <a:BarcodeNumber>
                    60000000425
                </a:BarcodeNumber>
                <a:CategoryId>
                    1
                </a:CategoryId>
                <a:Cost>
                    1250.0000
                </a:Cost>
                <a:DefaultPOLevel>
                    false
                </a:DefaultPOLevel>
                <a:DepartmentId>
                    1
                </a:DepartmentId>
                <a:Depth i:nil="true"/>
                <a:Description>
                    725 HUNTER 12G 28" M/C
                </a:Description>
            </a:ItemMaster>

2019-10-17T13:53:13.751Z
2019-10-17T13:58:13.751Z
假的
7.
60000000425
1.
1250
假的
1.
725 HUNTER 12G 28“M/C
您可以为此目的使用。 编写一个基于xpath的模板来指定要保留的属性,以及在json输出中如何命名;如下所示

范例

const{transform}=require('camaro')
常量fs=require('fs')
constxml=fs.readFileSync('examples/ean.xml','utf-8')
常量模板={
缓存键:'/hotellistreponse/cacheKey',
酒店:['//HotelSummary'{
酒店id:“hotelId”,
姓名:'姓名',
房间:[“RoomRate详细信息列表/RoomRate详细信息”{
费率:['RateInfos/RateInfo'{
货币:'ChargeableRateInfo/@currencyCode',
不可退还:'boolean(nonretailable=“true”),
价格:'number(ChargeableRateInfo/@total)'
}],
房间名称:'roomDescription',
房间类型\u id:“房间类型代码”
}]
}],
会话id:“/HotellisResponse/customerSessionId”
}
;(异步函数(){
常量结果=等待转换(xml、模板)
console.log(结果)
})()

您已经尝试了哪些方法但没有成功?