I get a XML file like this:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:udb="http://somenamespace>
<soap:Header/>
<soap:Body>
<udb:ProvideUDBIdentityInformationRequest>
<udb:RequestID>1</udb:RequestID>
<udb:IDnumber>1</udb:IDnumber>
<udb:UnifiedNumber>3</udb:UnifiedNumber>
</udb:ProvideUDBIdentityInformationRequest>
</soap:Body>
</soap:Envelope>
I want to save the below string to another file.
<soap:Body>
<udb:ProvideUDBIdentityInformationRequest>
<udb:RequestID>1</udb:RequestID>
<udb:IDnumber>1</udb:IDnumber>
<udb:UnifiedNumber>3</udb:UnifiedNumber>
</udb:ProvideUDBIdentityInformationRequest>
</soap:Body>
How can I achieve that ?
In fact, I've refer to some tutorial like this one ,http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlSlurper, but cannot find such a method in XmlSlurper.
Thanks in advance!
Assuming you have the original xml in a variable called xml, you can do:
String output = new groovy.xml.StreamingMarkupBuilder().bind {
mkp.yield new XmlSlurper().parseText( xml ).Body
}
Then, output equals:
<soap:Body xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>
<udb:ProvideUDBIdentityInformationRequest xmlns:udb='http://somenamespace'>
<udb:RequestID>1</udb:RequestID>
<udb:IDnumber>1</udb:IDnumber>
<udb:UnifiedNumber>3</udb:UnifiedNumber>
</udb:ProvideUDBIdentityInformationRequest>
</soap:Body>
Related
The WSDL in question is under the following URL: https://bmdweb.bmd.at/bmdntcswsdev/bmdntcsws.dll/wsdl/IBMDSOAPNTCS
I was provided with a sample log-output of how the XML should be constructed.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.bmd.at/" xmlns:types="http://www.bmd.at/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<q1:Login xmlns:q1="http://www.bmd.at/wws">
<ALoginRequest href="#id1" />
</q1:Login>
<q2:TBMDLoginRequest id="id1" xsi:type="q2:TBMDLoginRequest" xmlns:q2="http://www.bmd.at/soap">
<Auth href="#id2" />
</q2:TBMDLoginRequest>
<q3:TBMDPlainText id="id2" xsi:type="q3:TBMDPlainText" xmlns:q3="http://www.bmd.at/soap">
<Username xsi:type="xsd:string">xxxxUSER</Username>
<Password xsi:type="xsd:string">xxxxPASSWORD</Password>
<DBAlias xsi:type="xsd:string">xxxxDBALIAS</DBAlias>
</q3:TBMDPlainText>
</soap:Body>
</soap:Envelope>
Problem
I simply cannot figure out how to construct this XML using https://www.npmjs.com/package/soap. The part, where ALoginRequest is within the Login element, while everything else is outside of it, confuses me.
Efforts
When I try this: const login = await client.LoginAsync({ALoginRequest: {Auth: {TBMDPlainText: auth}}}), I get the following output.
<?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:tns="http://www.bmd.at/" xmlns:ns1="http://www.bmd.at/soap" xmlns:ns2="http://www.bmd.at/wws"><soap:Body><tns:Login><ALoginRequest><Auth><TBMDPlainText><Username>xxxx</Username><Password>xxxx</Password><DBAlias>xxxx</DBAlias></TBMDPlainText></Auth></ALoginRequest></tns:Login></soap:Body></soap:Envelope>
Can anyone provide me any hints?
I was wondering if someone has an example using SuiteTalk, i was searching but could not find any examples.
Here's a SOAP request that executes a customer search with the internal ID of the search.
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<tokenPassport xmlns="urn:messages_2019_2.platform.webservices.netsuite.com">
<account xmlns="urn:core_2019_2.platform.webservices.netsuite.com">**********</account>
<consumerKey xmlns="urn:core_2019_2.platform.webservices.netsuite.com">****************************************************************</consumerKey>
<token xmlns="urn:core_2019_2.platform.webservices.netsuite.com">****************************************************************</token>
<nonce xmlns="urn:core_2019_2.platform.webservices.netsuite.com">b591c9bfb56c406c9cf79252783dac7f</nonce>
<timestamp xmlns="urn:core_2019_2.platform.webservices.netsuite.com">1605312585</timestamp>
<signature algorithm="HMAC_SHA256" xmlns="urn:core_2019_2.platform.webservices.netsuite.com">********************************************</signature>
</tokenPassport>
</soap:Header>
<soap:Body>
<search xmlns="urn:messages_2019_2.platform.webservices.netsuite.com">
<searchRecord savedSearchId="366" xsi:type="q1:CustomerSearchAdvanced" xmlns:q1="urn:relationships_2019_2.lists.webservices.netsuite.com"/>
</search>
</soap:Body>
</soap:Envelope>
It looks like this with C#
var search = new CustomerSearchAdvanced()
{
savedSearchId = "366"
};
var results = ns.search(search);
I am trying to get the value of the attribute IntegratorCode AND ProductType using groovy.
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAPNYK1="http://www.w3.org/2001/XMLSchema"
xmlns:SOAPNYK2="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAPNYK3="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header>
<Authentication
xmlns="urn:iQQ:API:22:iQQMessages.xsd" EmployeeCode="*****" IntegratorCode="GENERIC" Pwd="******" Usr="SYSUSER"/>
</soap:Header>
<soap:Body>
<CanOfferProduct
xmlns="urn:iQQ:API:22:iQQMessages.xsd">
<OnQuotePackage
xmlns="" ProductType="GAP" QuoteNumber="74859">test
</OnQuotePackage>/>
</CanOfferProduct>
</soap:Body>
</soap:Envelope>
I tried the following method using XmlSlurpur
def result = new XmlSlurper().parseText(xml)
println(result.Envelope.Header[1].Authentication.#IntegratorCode)
//output = IntegratorCode
I wanted to print the value of IntegratorCode which is "GENERIC".
I am not sure what I am doing wrong in this case. please help.
what you called result is soap:Envelope, so you essentially had Envelope.Envelope... This works:
println result.Header.Authentication.#IntegratorCode
As a precaution I normally use it like this:
def Envelope = new XmlSlurper().parseText(xml)
I have a string describing a XML object, containing line-breaks and spaces, like so:
<?xml version="1.0" encoding="UTF-8"?>
<play>
<scenario>
<author>Arthur Drake</author>
<title> ...til I get there</title>
</scenario>
</play>
And I'd like to convert it like so all unnecessary characters are removed:
<?xml version="1.0" encoding="UTF-8"?><play><scenario><author>Arthur Drake</author><title> ...til I get there</title></scenario></play>
Note that the whitespaces inside the nodes should be left untouched.
What is the best solution to do so in Node.js ?
This code should give you the result you're looking for:
let xml =
`<?xml version="1.0" encoding="UTF-8"?>
<play>
<scenario>
<author>Arthur Drake</author>
<title> ...til I get there</title>
</scenario>
</play>`;
console.log('Initial xml:', xml);
function trimXml(xml) {
return xml.replace(/>\s+</g, "><");
}
console.log('\nTrimmed xml:', trimXml(xml));
I'd like to parse an XML document (SOAP request message) for a particular element. The document is stored in requestContent and looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:udb="http://somenamespace>
<soap:Header/>
<soap:Body>
<udb:ProvideUDBIdentityInformationRequest>
<udb:RequestID>1</udb:RequestID>
<udb:IDnumber>1</udb:IDnumber>
<udb:UnifiedNumber>3</udb:UnifiedNumber>
</udb:ProvideUDBIdentityInformationRequest>
</soap:Body>
</soap:Envelope>
My Groovy code looks like this:
def request = new XmlSlurper().parseText(requestContent)
println request.ProvideUDBIdentityInformationRequest.RequestID
However the output is empty whereas I would have expected a "1".
Thanks,
Robert
Can you try:
println request.Body.ProvideUDBIdentityInformationRequest.RequestID
(you also have a " missing from the end of the xml declaration, but I guess that's a cut/paste error?)