use xml2js parseString return valueUsing SOAP to access webservices - failing on soapclient()disabling namespace attributes in serializationWhat value we have to give for match in template tag?Read SOAP XML by ASMX web servcie functionError using node-soap in NodeJSXMLSchema and XMLSchema-instance namespaces without schemaLocationHow to get data from XML Column that contain xml namespace (SQL Server 2005)Parsing JSON response in iOS appImport XML into SQL server using OPENXML command with XMLNSDatastage Rest call in Hierarchical step
What exact color does ozone gas have?
PTIJ: Haman's bad computer
Calculating total slots
Why did the EU agree to delay the Brexit deadline?
Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?
Mimic lecturing on blackboard, facing audience
How does a computer interpret real numbers?
What is the evidence for the "tyranny of the majority problem" in a direct democracy context?
How to hide some fields of struct in C?
Fear of getting stuck on one programming language / technology that is not used in my country
Is there a RAID 0 Equivalent for RAM?
What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?
What does "Scientists rise up against statistical significance" mean? (Comment in Nature)
Strong empirical falsification of quantum mechanics based on vacuum energy density
How can I write humor as character trait?
Terse Method to Swap Lowest for Highest?
What happens if you are holding an Iron Flask with a demon inside and walk into an Antimagic Field?
Can a College of Swords bard use a Blade Flourish option on an opportunity attack provoked by their own Dissonant Whispers spell?
Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?
Do the primes contain an infinite almost arithmetic progression?
What should you do when eye contact makes your subordinate uncomfortable?
Is there an injective, monotonically increasing, strictly concave function from the reals, to the reals?
Yosemite Fire Rings - What to Expect?
Quoting Keynes in a lecture
use xml2js parseString return value
Using SOAP to access webservices - failing on soapclient()disabling namespace attributes in serializationWhat value we have to give for match in template tag?Read SOAP XML by ASMX web servcie functionError using node-soap in NodeJSXMLSchema and XMLSchema-instance namespaces without schemaLocationHow to get data from XML Column that contain xml namespace (SQL Server 2005)Parsing JSON response in iOS appImport XML into SQL server using OPENXML command with XMLNSDatastage Rest call in Hierarchical step
xml = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCurrentRoomStatusGraphResponse xmlns="www.example.com"><GetCurrentRoomStatusGraphResult><RoomStatusGraphItem><RoomID>3</RoomID><ChainID>1</ChainID><RoomNo>8888</RoomNo><RoomTypeID>1</RoomTypeID><RoomTypeCode>DF</RoomTypeCode><RoomTypeName>standard room</RoomTypeName><RoomRate>0.0000</RoomRate><Floor>2</Floor><FolioID>123456</FolioID><Guest><RoomStatusGuest><Name>Jon Snow</Name><Sex>1</Sex><VipTypeID>0</VipTypeID></RoomStatusGuest></Guest><Arrival>2019-03-07T13:43:00</Arrival><Depart>2019-03-08T12:00:00</Depart><IsDepart>false</IsDepart><IsTimeRoom>false</IsTimeRoom><Surreptitious>false</Surreptitious><CheckInState>CheckIn</CheckInState><ClentState>NoClean</ClentState><HouseKeepState>EnableSaleRoom</HouseKeepState><CheckRoomFlag>false</CheckRoomFlag><IsBookInRoom>false</IsBookInRoom><IsFreeRoom>false</IsFreeRoom><IsInnerRoom>true</IsInnerRoom><IsThirdOTA>false</IsThirdOTA><IsAssociationRoom>false</IsAssociationRoom><RoomRemark /><FolioInnerRemark /><FolioRemark /><AddtionalFlag><int>1</int></AddtionalFlag><IsReserve>false</IsReserve><ClearRoomType>3</ClearRoomType><ClearRoomTypeName>normal</ClearRoomTypeName><CheckOutID>0</CheckOutID><CheckOutState>None</CheckOutState><MilkMarketStatus>0</MilkMarketStatus></RoomStatusGraphItem></GetCurrentRoomStatusGraphResult></GetCurrentRoomStatusGraphResponse></soap:Body></soap:Envelope>'
var parseString = require('xml2js').parseString;
parseString(xml, function (err, result)
console.dir(result); //print object user console.log (util.inspect(result, false,null)) can print all value
);
I want another function use this value, how to return the value?
like this
parseString(xml, function (err, result)
return result
);
node.js json xml xml2js
add a comment |
xml = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCurrentRoomStatusGraphResponse xmlns="www.example.com"><GetCurrentRoomStatusGraphResult><RoomStatusGraphItem><RoomID>3</RoomID><ChainID>1</ChainID><RoomNo>8888</RoomNo><RoomTypeID>1</RoomTypeID><RoomTypeCode>DF</RoomTypeCode><RoomTypeName>standard room</RoomTypeName><RoomRate>0.0000</RoomRate><Floor>2</Floor><FolioID>123456</FolioID><Guest><RoomStatusGuest><Name>Jon Snow</Name><Sex>1</Sex><VipTypeID>0</VipTypeID></RoomStatusGuest></Guest><Arrival>2019-03-07T13:43:00</Arrival><Depart>2019-03-08T12:00:00</Depart><IsDepart>false</IsDepart><IsTimeRoom>false</IsTimeRoom><Surreptitious>false</Surreptitious><CheckInState>CheckIn</CheckInState><ClentState>NoClean</ClentState><HouseKeepState>EnableSaleRoom</HouseKeepState><CheckRoomFlag>false</CheckRoomFlag><IsBookInRoom>false</IsBookInRoom><IsFreeRoom>false</IsFreeRoom><IsInnerRoom>true</IsInnerRoom><IsThirdOTA>false</IsThirdOTA><IsAssociationRoom>false</IsAssociationRoom><RoomRemark /><FolioInnerRemark /><FolioRemark /><AddtionalFlag><int>1</int></AddtionalFlag><IsReserve>false</IsReserve><ClearRoomType>3</ClearRoomType><ClearRoomTypeName>normal</ClearRoomTypeName><CheckOutID>0</CheckOutID><CheckOutState>None</CheckOutState><MilkMarketStatus>0</MilkMarketStatus></RoomStatusGraphItem></GetCurrentRoomStatusGraphResult></GetCurrentRoomStatusGraphResponse></soap:Body></soap:Envelope>'
var parseString = require('xml2js').parseString;
parseString(xml, function (err, result)
console.dir(result); //print object user console.log (util.inspect(result, false,null)) can print all value
);
I want another function use this value, how to return the value?
like this
parseString(xml, function (err, result)
return result
);
node.js json xml xml2js
add a comment |
xml = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCurrentRoomStatusGraphResponse xmlns="www.example.com"><GetCurrentRoomStatusGraphResult><RoomStatusGraphItem><RoomID>3</RoomID><ChainID>1</ChainID><RoomNo>8888</RoomNo><RoomTypeID>1</RoomTypeID><RoomTypeCode>DF</RoomTypeCode><RoomTypeName>standard room</RoomTypeName><RoomRate>0.0000</RoomRate><Floor>2</Floor><FolioID>123456</FolioID><Guest><RoomStatusGuest><Name>Jon Snow</Name><Sex>1</Sex><VipTypeID>0</VipTypeID></RoomStatusGuest></Guest><Arrival>2019-03-07T13:43:00</Arrival><Depart>2019-03-08T12:00:00</Depart><IsDepart>false</IsDepart><IsTimeRoom>false</IsTimeRoom><Surreptitious>false</Surreptitious><CheckInState>CheckIn</CheckInState><ClentState>NoClean</ClentState><HouseKeepState>EnableSaleRoom</HouseKeepState><CheckRoomFlag>false</CheckRoomFlag><IsBookInRoom>false</IsBookInRoom><IsFreeRoom>false</IsFreeRoom><IsInnerRoom>true</IsInnerRoom><IsThirdOTA>false</IsThirdOTA><IsAssociationRoom>false</IsAssociationRoom><RoomRemark /><FolioInnerRemark /><FolioRemark /><AddtionalFlag><int>1</int></AddtionalFlag><IsReserve>false</IsReserve><ClearRoomType>3</ClearRoomType><ClearRoomTypeName>normal</ClearRoomTypeName><CheckOutID>0</CheckOutID><CheckOutState>None</CheckOutState><MilkMarketStatus>0</MilkMarketStatus></RoomStatusGraphItem></GetCurrentRoomStatusGraphResult></GetCurrentRoomStatusGraphResponse></soap:Body></soap:Envelope>'
var parseString = require('xml2js').parseString;
parseString(xml, function (err, result)
console.dir(result); //print object user console.log (util.inspect(result, false,null)) can print all value
);
I want another function use this value, how to return the value?
like this
parseString(xml, function (err, result)
return result
);
node.js json xml xml2js
xml = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCurrentRoomStatusGraphResponse xmlns="www.example.com"><GetCurrentRoomStatusGraphResult><RoomStatusGraphItem><RoomID>3</RoomID><ChainID>1</ChainID><RoomNo>8888</RoomNo><RoomTypeID>1</RoomTypeID><RoomTypeCode>DF</RoomTypeCode><RoomTypeName>standard room</RoomTypeName><RoomRate>0.0000</RoomRate><Floor>2</Floor><FolioID>123456</FolioID><Guest><RoomStatusGuest><Name>Jon Snow</Name><Sex>1</Sex><VipTypeID>0</VipTypeID></RoomStatusGuest></Guest><Arrival>2019-03-07T13:43:00</Arrival><Depart>2019-03-08T12:00:00</Depart><IsDepart>false</IsDepart><IsTimeRoom>false</IsTimeRoom><Surreptitious>false</Surreptitious><CheckInState>CheckIn</CheckInState><ClentState>NoClean</ClentState><HouseKeepState>EnableSaleRoom</HouseKeepState><CheckRoomFlag>false</CheckRoomFlag><IsBookInRoom>false</IsBookInRoom><IsFreeRoom>false</IsFreeRoom><IsInnerRoom>true</IsInnerRoom><IsThirdOTA>false</IsThirdOTA><IsAssociationRoom>false</IsAssociationRoom><RoomRemark /><FolioInnerRemark /><FolioRemark /><AddtionalFlag><int>1</int></AddtionalFlag><IsReserve>false</IsReserve><ClearRoomType>3</ClearRoomType><ClearRoomTypeName>normal</ClearRoomTypeName><CheckOutID>0</CheckOutID><CheckOutState>None</CheckOutState><MilkMarketStatus>0</MilkMarketStatus></RoomStatusGraphItem></GetCurrentRoomStatusGraphResult></GetCurrentRoomStatusGraphResponse></soap:Body></soap:Envelope>'
var parseString = require('xml2js').parseString;
parseString(xml, function (err, result)
console.dir(result); //print object user console.log (util.inspect(result, false,null)) can print all value
);
I want another function use this value, how to return the value?
like this
parseString(xml, function (err, result)
return result
);
node.js json xml xml2js
node.js json xml xml2js
asked Mar 7 at 6:26
毕兴涛毕兴涛
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use the async / await pattern to do this, for example:
const parseString = require('xml2js').parseString;
const xmlInput = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCurrentRoomStatusGraphResponse xmlns="www.example.com"><GetCurrentRoomStatusGraphResult><RoomStatusGraphItem><RoomID>3</RoomID><ChainID>1</ChainID><RoomNo>8888</RoomNo><RoomTypeID>1</RoomTypeID><RoomTypeCode>DF</RoomTypeCode><RoomTypeName>standard room</RoomTypeName><RoomRate>0.0000</RoomRate><Floor>2</Floor><FolioID>123456</FolioID><Guest><RoomStatusGuest><Name>Jon Snow</Name><Sex>1</Sex><VipTypeID>0</VipTypeID></RoomStatusGuest></Guest><Arrival>2019-03-07T13:43:00</Arrival><Depart>2019-03-08T12:00:00</Depart><IsDepart>false</IsDepart><IsTimeRoom>false</IsTimeRoom><Surreptitious>false</Surreptitious><CheckInState>CheckIn</CheckInState><ClentState>NoClean</ClentState><HouseKeepState>EnableSaleRoom</HouseKeepState><CheckRoomFlag>false</CheckRoomFlag><IsBookInRoom>false</IsBookInRoom><IsFreeRoom>false</IsFreeRoom><IsInnerRoom>true</IsInnerRoom><IsThirdOTA>false</IsThirdOTA><IsAssociationRoom>false</IsAssociationRoom><RoomRemark /><FolioInnerRemark /><FolioRemark /><AddtionalFlag><int>1</int></AddtionalFlag><IsReserve>false</IsReserve><ClearRoomType>3</ClearRoomType><ClearRoomTypeName>normal</ClearRoomTypeName><CheckOutID>0</CheckOutID><CheckOutState>None</CheckOutState><MilkMarketStatus>0</MilkMarketStatus></RoomStatusGraphItem></GetCurrentRoomStatusGraphResult></GetCurrentRoomStatusGraphResponse></soap:Body></soap:Envelope>';
function parseXml(xml)
return new Promise((resolve, reject) =>
parseString(xml, (err, result) =>
if (err)
reject(err);
else
resolve(result);
);
);
function processResult(result)
console.log("processResult: result: ", result);
async function testXmlParse(xml)
try
let result = await parseXml(xml);
// Now that you have the result you can do further processing, write to file etc.
processResult(result);
catch (err)
console.error("parseXml failed: ", err);
testXmlParse(xmlInput);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037332%2fuse-xml2js-parsestring-return-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the async / await pattern to do this, for example:
const parseString = require('xml2js').parseString;
const xmlInput = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCurrentRoomStatusGraphResponse xmlns="www.example.com"><GetCurrentRoomStatusGraphResult><RoomStatusGraphItem><RoomID>3</RoomID><ChainID>1</ChainID><RoomNo>8888</RoomNo><RoomTypeID>1</RoomTypeID><RoomTypeCode>DF</RoomTypeCode><RoomTypeName>standard room</RoomTypeName><RoomRate>0.0000</RoomRate><Floor>2</Floor><FolioID>123456</FolioID><Guest><RoomStatusGuest><Name>Jon Snow</Name><Sex>1</Sex><VipTypeID>0</VipTypeID></RoomStatusGuest></Guest><Arrival>2019-03-07T13:43:00</Arrival><Depart>2019-03-08T12:00:00</Depart><IsDepart>false</IsDepart><IsTimeRoom>false</IsTimeRoom><Surreptitious>false</Surreptitious><CheckInState>CheckIn</CheckInState><ClentState>NoClean</ClentState><HouseKeepState>EnableSaleRoom</HouseKeepState><CheckRoomFlag>false</CheckRoomFlag><IsBookInRoom>false</IsBookInRoom><IsFreeRoom>false</IsFreeRoom><IsInnerRoom>true</IsInnerRoom><IsThirdOTA>false</IsThirdOTA><IsAssociationRoom>false</IsAssociationRoom><RoomRemark /><FolioInnerRemark /><FolioRemark /><AddtionalFlag><int>1</int></AddtionalFlag><IsReserve>false</IsReserve><ClearRoomType>3</ClearRoomType><ClearRoomTypeName>normal</ClearRoomTypeName><CheckOutID>0</CheckOutID><CheckOutState>None</CheckOutState><MilkMarketStatus>0</MilkMarketStatus></RoomStatusGraphItem></GetCurrentRoomStatusGraphResult></GetCurrentRoomStatusGraphResponse></soap:Body></soap:Envelope>';
function parseXml(xml)
return new Promise((resolve, reject) =>
parseString(xml, (err, result) =>
if (err)
reject(err);
else
resolve(result);
);
);
function processResult(result)
console.log("processResult: result: ", result);
async function testXmlParse(xml)
try
let result = await parseXml(xml);
// Now that you have the result you can do further processing, write to file etc.
processResult(result);
catch (err)
console.error("parseXml failed: ", err);
testXmlParse(xmlInput);
add a comment |
You can use the async / await pattern to do this, for example:
const parseString = require('xml2js').parseString;
const xmlInput = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCurrentRoomStatusGraphResponse xmlns="www.example.com"><GetCurrentRoomStatusGraphResult><RoomStatusGraphItem><RoomID>3</RoomID><ChainID>1</ChainID><RoomNo>8888</RoomNo><RoomTypeID>1</RoomTypeID><RoomTypeCode>DF</RoomTypeCode><RoomTypeName>standard room</RoomTypeName><RoomRate>0.0000</RoomRate><Floor>2</Floor><FolioID>123456</FolioID><Guest><RoomStatusGuest><Name>Jon Snow</Name><Sex>1</Sex><VipTypeID>0</VipTypeID></RoomStatusGuest></Guest><Arrival>2019-03-07T13:43:00</Arrival><Depart>2019-03-08T12:00:00</Depart><IsDepart>false</IsDepart><IsTimeRoom>false</IsTimeRoom><Surreptitious>false</Surreptitious><CheckInState>CheckIn</CheckInState><ClentState>NoClean</ClentState><HouseKeepState>EnableSaleRoom</HouseKeepState><CheckRoomFlag>false</CheckRoomFlag><IsBookInRoom>false</IsBookInRoom><IsFreeRoom>false</IsFreeRoom><IsInnerRoom>true</IsInnerRoom><IsThirdOTA>false</IsThirdOTA><IsAssociationRoom>false</IsAssociationRoom><RoomRemark /><FolioInnerRemark /><FolioRemark /><AddtionalFlag><int>1</int></AddtionalFlag><IsReserve>false</IsReserve><ClearRoomType>3</ClearRoomType><ClearRoomTypeName>normal</ClearRoomTypeName><CheckOutID>0</CheckOutID><CheckOutState>None</CheckOutState><MilkMarketStatus>0</MilkMarketStatus></RoomStatusGraphItem></GetCurrentRoomStatusGraphResult></GetCurrentRoomStatusGraphResponse></soap:Body></soap:Envelope>';
function parseXml(xml)
return new Promise((resolve, reject) =>
parseString(xml, (err, result) =>
if (err)
reject(err);
else
resolve(result);
);
);
function processResult(result)
console.log("processResult: result: ", result);
async function testXmlParse(xml)
try
let result = await parseXml(xml);
// Now that you have the result you can do further processing, write to file etc.
processResult(result);
catch (err)
console.error("parseXml failed: ", err);
testXmlParse(xmlInput);
add a comment |
You can use the async / await pattern to do this, for example:
const parseString = require('xml2js').parseString;
const xmlInput = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCurrentRoomStatusGraphResponse xmlns="www.example.com"><GetCurrentRoomStatusGraphResult><RoomStatusGraphItem><RoomID>3</RoomID><ChainID>1</ChainID><RoomNo>8888</RoomNo><RoomTypeID>1</RoomTypeID><RoomTypeCode>DF</RoomTypeCode><RoomTypeName>standard room</RoomTypeName><RoomRate>0.0000</RoomRate><Floor>2</Floor><FolioID>123456</FolioID><Guest><RoomStatusGuest><Name>Jon Snow</Name><Sex>1</Sex><VipTypeID>0</VipTypeID></RoomStatusGuest></Guest><Arrival>2019-03-07T13:43:00</Arrival><Depart>2019-03-08T12:00:00</Depart><IsDepart>false</IsDepart><IsTimeRoom>false</IsTimeRoom><Surreptitious>false</Surreptitious><CheckInState>CheckIn</CheckInState><ClentState>NoClean</ClentState><HouseKeepState>EnableSaleRoom</HouseKeepState><CheckRoomFlag>false</CheckRoomFlag><IsBookInRoom>false</IsBookInRoom><IsFreeRoom>false</IsFreeRoom><IsInnerRoom>true</IsInnerRoom><IsThirdOTA>false</IsThirdOTA><IsAssociationRoom>false</IsAssociationRoom><RoomRemark /><FolioInnerRemark /><FolioRemark /><AddtionalFlag><int>1</int></AddtionalFlag><IsReserve>false</IsReserve><ClearRoomType>3</ClearRoomType><ClearRoomTypeName>normal</ClearRoomTypeName><CheckOutID>0</CheckOutID><CheckOutState>None</CheckOutState><MilkMarketStatus>0</MilkMarketStatus></RoomStatusGraphItem></GetCurrentRoomStatusGraphResult></GetCurrentRoomStatusGraphResponse></soap:Body></soap:Envelope>';
function parseXml(xml)
return new Promise((resolve, reject) =>
parseString(xml, (err, result) =>
if (err)
reject(err);
else
resolve(result);
);
);
function processResult(result)
console.log("processResult: result: ", result);
async function testXmlParse(xml)
try
let result = await parseXml(xml);
// Now that you have the result you can do further processing, write to file etc.
processResult(result);
catch (err)
console.error("parseXml failed: ", err);
testXmlParse(xmlInput);
You can use the async / await pattern to do this, for example:
const parseString = require('xml2js').parseString;
const xmlInput = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCurrentRoomStatusGraphResponse xmlns="www.example.com"><GetCurrentRoomStatusGraphResult><RoomStatusGraphItem><RoomID>3</RoomID><ChainID>1</ChainID><RoomNo>8888</RoomNo><RoomTypeID>1</RoomTypeID><RoomTypeCode>DF</RoomTypeCode><RoomTypeName>standard room</RoomTypeName><RoomRate>0.0000</RoomRate><Floor>2</Floor><FolioID>123456</FolioID><Guest><RoomStatusGuest><Name>Jon Snow</Name><Sex>1</Sex><VipTypeID>0</VipTypeID></RoomStatusGuest></Guest><Arrival>2019-03-07T13:43:00</Arrival><Depart>2019-03-08T12:00:00</Depart><IsDepart>false</IsDepart><IsTimeRoom>false</IsTimeRoom><Surreptitious>false</Surreptitious><CheckInState>CheckIn</CheckInState><ClentState>NoClean</ClentState><HouseKeepState>EnableSaleRoom</HouseKeepState><CheckRoomFlag>false</CheckRoomFlag><IsBookInRoom>false</IsBookInRoom><IsFreeRoom>false</IsFreeRoom><IsInnerRoom>true</IsInnerRoom><IsThirdOTA>false</IsThirdOTA><IsAssociationRoom>false</IsAssociationRoom><RoomRemark /><FolioInnerRemark /><FolioRemark /><AddtionalFlag><int>1</int></AddtionalFlag><IsReserve>false</IsReserve><ClearRoomType>3</ClearRoomType><ClearRoomTypeName>normal</ClearRoomTypeName><CheckOutID>0</CheckOutID><CheckOutState>None</CheckOutState><MilkMarketStatus>0</MilkMarketStatus></RoomStatusGraphItem></GetCurrentRoomStatusGraphResult></GetCurrentRoomStatusGraphResponse></soap:Body></soap:Envelope>';
function parseXml(xml)
return new Promise((resolve, reject) =>
parseString(xml, (err, result) =>
if (err)
reject(err);
else
resolve(result);
);
);
function processResult(result)
console.log("processResult: result: ", result);
async function testXmlParse(xml)
try
let result = await parseXml(xml);
// Now that you have the result you can do further processing, write to file etc.
processResult(result);
catch (err)
console.error("parseXml failed: ", err);
testXmlParse(xmlInput);
edited Mar 7 at 9:14
answered Mar 7 at 8:57
Terry LennoxTerry Lennox
5,3112718
5,3112718
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037332%2fuse-xml2js-parsestring-return-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown