SAXParseException while executing Karate script - karate

My response data is having text in it.
I am not able to get data from any of the fields using xpath from this response.
Karate shows "xml parsing failed, response data type set to string: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 716; The entity "nbsp" was referenced, but not declared." all xpaths
(Eg: response/transaction/values/data/#name)
I need to verify the commentDisplay tag in below xml. How to proceed?/ Is there any way to remove before fetching the value using xpath?
<Response>
<RequestID>1234</RequestID>
<transaction>
<values>
<data name="firstName">Sumith</data>
<data name="lastName">Menon</data>
</values>
<commentDisplay>
<top>Please Verify IDCard</top>
<bottom/></commentDisplay>
</transaction>
</Response>

is invalid in XML, refer: https://stackoverflow.com/a/36097922/143475
But you can correct this in one step:
* xml response = response.replaceAll(' ', ' ')

Related

Karate "match contains" for xml does not work like JSON [duplicate]

This question already has an answer here:
How to compare XML response with Json in Karate
(1 answer)
Closed 1 year ago.
I've noticed that "match contains" for checking if xml structure contains in another xml structure works differently than json counterpart. To give you an example :
* def expectedResult =
"""
<?xml version="1.0" encoding="UTF-8"?>
<response>
<id>1</id>
<id>2</id>
<id>3</id>
</response>
"""
* header Accept = xml
Given path 'some\path'
When method GET
Then status 200
## If response contains -
## <response><id>1</id></response>
## The following match will fail with -
## "actual and expected arrays are not the same size - 1:3"
And match response contains expectedResult
If it's a JSON structure, it will pass because 1 contains in the list of 1,2,3. But in XML, it's still checking array size. Is that how it suppose to work?
Update : This is not the same question as the other question. I'm trying to compare reference XML file that I have with XML structure being returned from the API. The question you linked to is comparing JSON reference file to XML response. So, that begs the question, in karate, do I have to convert my reference XML and response XML to json just to perform "contains"?
XML has some fundamental "shape" differences from JSON. I leave it to you to figure out, one of the challenges is the concept of a "root" tag, which JSON does not have. So they will not "match up" the way you may expect.
One tip - convert XML to JSON if in doubt. Here is an example:
* def expected =
"""
<?xml version="1.0" encoding="UTF-8"?>
<response>
<id>1</id>
<id>2</id>
<id>3</id>
</response>
"""
* json temp = $expected/response
* match temp.response.id == ['1', '2', '3']

Mule: DataMapper - CSV to XML Conversion , Final XML is not formatted with root element

I'm new to mule, working with Matamapper which converts csv file to xml. I'm able to convert csv to xml . But the final output response is not formatted with actual root element. Please find my final output xml structure. It doesnt have root element. Kindly guide me . If this is correct, help me how to insert root element. ( Bcz i tried Set payload to insert the root element) it is not working correclty.
<?xml version="1.0" encoding="UTF-8"?>
<employees>
<name>jothi</name>
<street>123, main</street>
</employees>
<employees>
<name>Jane </name>
<street>Main Street</street>
</employees>
Also referred : csv to xml: not sure the best way to do it in Mule ESB
http://www.mulesoft.org/documentation/display/current/DataMapper+Flat-to-Structured+and+Structured-to-Flat+Mapping - giving errors in datamapper
Thank you.
Upgrading MuleStudio to 3.5 cleaned up a lot of the errors I was seeing using the DataMapper

how to get node name in Oracle SQL extract() with xPath (10g)

Here is a XML file:
<ROOT>
<A>
<B>2</B>
<C>3</C>
<D>4</D>
</A>
</ROOT>
How to get the tag name "C" through xPath. The function name() does not work here in extract.
It reports Errors:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token
gXmlDOM is the xml string above, how to do this in SQL?
select XMLType(gXmlDOM).extract(p_xmlPath).getStringVal() from dual;
This might be what you're looking for...
Select xmltype('<ROOT><A><B>2</B><C>3</C><D>4</D></A></ROOT>')
.extract('ROOT/A/*[2]')
.getrootelement()
From dual;

Parsing using NSXMLParser

I am being returned some XML from a web service. Basically, the xml looks like this:
<response>
<data>
More XML here but the it's escaped by XML entities
</data>
</response>
so, as you can see, I have xml that is valid, but the stuff inside data tag is escaped with XML entities. what's the best (most efficient) way for me to feed this into the parser?
What I am doing right now is, when I get the data from web service, I convert it into NSString....then replace the "XML escaped entities" with real ones.....then convert it back into NSData...then feed it into the parser. This doesn't seem like a very good solution so I was wondering if there's a better way to do it?
Thanks.
Alright, here's the xml that I am getting:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><ActivityId CorrelationId="d39007b5-ee69-41c7-a61d-831b456f9ea3" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">aa88d1cd-253c-48d1-abeb-62a880bea806</ActivityId></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><LoginResponse xmlns="http://MSS"><LoginResult><LoginInformation>
<User>
<UserID>612</UserID>
<UserName>Demo User</UserName>
<Email>mssdev#mss-mail.com</Email>
<CompanyID>17034</CompanyID>
<CompanyName>PlanET Demonstration Agency</CompanyName>
</User>
</LoginInformation></LoginResult></LoginResponse></s:Body></s:Envelope>
As you can see, everything in is escaped.
That's kind of horrifying. Why don't you just take the contents of that tag (e.g. the data with the entities) and just pass that through another NSXMLParser? The first parser will have decoded the entities, and the second parser will be presented with the decoded version of the contents of that tag.

Extract HTML from CDATA node in iPhone

<item>
<data>
<![CDATA[
<p>Test</p>
<p><strong>Hi!</strong><br />Hello.</p>
]]>
</data>
</item>
Using TouchXML/NSXMLParser How can i extract only the HTML part into a string/appropriate data format so that I can display it in a UIWebView?
It's definitely possible: http://code.google.com/p/touchcode/issues/detail?id=36&can=1&q=cdata
TouchXML will parse it automatically. If you retrieve the stringValue of the CXMLElement you will get the full "raw" html back, properly formed.