Ask a Question

GroovyUtils XMLHolder throwing Xpath syntax error when XML node value contains escaped character.

tadudek
Occasional Contributor

GroovyUtils XMLHolder throwing Xpath syntax error when XML node value contains escaped character.

GroovyUtils throwing error when XML node value contains escaped characters. 

 

In my script, I'm accessing a node that contains the description of an error. That node when read by my XMLHolder throws this error: 

 

  • Caused by: java.lang.RuntimeException: net.sf.saxon.trans.XPathException: XPath syntax error at char 9 on line 2 in {\nInvalid part number}:
  • Unexpected token name "part" beyond end of expression

It appears that the node I'm reading contains the value "\n", and when the holder tries to read it, it throws the error. 

 

How can I read the node, with the escaped value, and not bomb out?

 

 

12 REPLIES 12
nmrao
Community Hero

Can you please show the sample data? Does it has string literal "\n"?


Regards,
Rao.
tadudek
Occasional Contributor

Here's the output from the log: 

 

Tue Mar 31 15:45:21 MDT 2020: INFO: <?xml version="1.0" encoding="UTF-8"?>
<errorDescription xmlns:p="http://www.ournamespace.com">Invalid part number</errorDescription>

It appears to be a non-printable char. I also just edited the namespace, as not put publish it on the forum. 

nmrao
Community Hero

Difficult to predict.

Is your request data valid?

Please see if below link is of any help
https://stackoverflow.com/questions/12549029/sql-error-ora-01722-invalid-number


Regards,
Rao.
tadudek
Occasional Contributor

@nmrao 

 

I don't control the values being passed back in this response. So, I'm trying to grab the value (which comes out as a string if I use the holder.getNodeValue(xpath). That breaks, but I'm trying to get it into an excel file so that as I'm going through my response, if one of these items in my xml list has an error, I transcribe that to the file. 

 

To get around it, it appears that I may be able to do something like this: 

	log.info holder.getDomNode(err).toString()

But, it's not exactly what I want. 

 

Ideally, I just want pull what's there, regardless printable/non-printable chars. So, if I could just CDATA the content regardless of what's there, but the problem is, is that I can't get to it. 

nmrao
Community Hero

How does the raw response look like? Text message and screen shot helps.

Would try below snippet in script assertion

assert context.response, 'Response empty or null'
log.info context.response


Regards,
Rao.
tadudek
Occasional Contributor

@nmrao 

 

I can't really post my full reponse here from the HTTP log. It does come back in escaped values, shown here.

 

 

2020-04-02 12-37-17_Window.png

The RAW view in the response test step also will not let me scroll to copy the entire raw response. So, the error in question is too far over, and readyapi won't let me scroll over to see it. 

nmrao
Community Hero

Hmm.
Have you checked with you team regarding this?
Also there is header "Content-Encoding" header with gzip.
Are you sending any header related to this?
Also check the documentation below if you have preferences set to receive compressed response . Try changing it in case needed.
https://www.soapui.org/docs/preferences-and-settings.html#HTTP-Settings


Regards,
Rao.
richie
Community Hero

Hi @tadudek,

It looks like Rao's got the right idea. Your response is being served gzip compressed which is why it looks a mess.
I think you have a choice here. You can either change the Accept-encoding header value on request to remove gzip (which can work, but not always...depends om server), OR
There's a checkbox on the http settings Rao pointed you to...'accept compressed response from host', you could disable this. I think the label of the checkbox is a little misleading...i read this like it means soapui cant receive compressed responses but the help thats been published reads like it decodes compressed responses.

Also you previously mentioned non utf-8 valid characters and CDATA in your response. If this is still relevant you can use an event handler to strip out CDATA tag handlers and non utf-8 characters on a response meaning ReadyAPI!'s xml parser will be able to successfully read the data in response.
Finally, in regards to not being able to view all of a response in your RAW tab, you can highlight some of the text in the RAW tab, grab it, copy and paste it out so you can view all detail in RAW if necessary.

Cheers

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
sonya_m
SmartBear Alumni (Retired)

Thank you for helping richie and nmrao!

 

@tadudek did you try impementing what the Community suggests? Please share your progress with usSmiley Happy


Sonya Mihaljova
Community and Education Specialist

cancel
Showing results for 
Search instead for 
Did you mean: