FHIR XML Patch Operation - Minimal Working Example - hl7-fhir

could someone provide me with a MWE for a FHIR PATCH operation in XML format on the public test.fhir.org test server. This is what I got:
Request:
PATCH http://test.fhir.org/r4/Patient/12345
Content-Type: application/xml-patch+xml
<replace sel="/name/family/#value">Schmidt</replace>
Error:
Error parsing resource Xml (This does not appear to be a FHIR element or resource (wrong namespace "") # /)
I similiar JSON operation woks fine:
PATCH http://test.fhir.org/r4/Patient/12345
Content-Type: application/json-patch+json
[{
"op": "replace",
"path": "/name/0/family",
"value": "Meyer"
}]
I've searched a lot and couldn't find an MWE for an XML Patch operation, only JSON.
Best
Tobias

You are missing the XML namespace. If you add this line to create a valid XML document, it should work:
<?xml version="1.0" encoding="UTF-8"?>

Related

ant.xslt/Xalan fails referencing namespaced nodes from an external file

In an .xsl file I want to use nodes from a separate file ("foo.xsd"). The .xsl file uses an explicit namespace prefix, the external file doesn't but rather relies on a default namespace. Their namespace URIs match up.
Reading in the nodes, with ant.xslt the following XPath expression results in an ArrayIndexOutOfBounds exception later
document('foo.xsd')/xsd:schema/xsd:*
while it works when removing the last reference to the namespace prefix
document('foo.xsd')/xsd:schema/*
Here is a minimal example that reproduces the issue. The transformation input file
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="bar"/>
</schema>
and a transformation .xsl file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
version="1.0">
<xsl:variable name="nodeSet" select="document('foo.xsd')/xsd:schema/xsd:*[#name]"/>
<xsl:template match="/xsd:schema/xsd:element">
<xsl:value-of select="$nodeSet/#name"/>
</xsl:template>
</xsl:stylesheet>
The referenced foo.xsd is just a copy of the input file, so in this cut down example I'm running over one instance of the file and reading in the other instance in the stylesheet.
Goold ol' xsltproc is extracting the right attribute value ("bar"). ant.xslt with the default processor (Xalan) throws an ArrayIndexOutOfBoundsException (I presume when looking for the colon insided the element name).The problem only arises when referencing nodeSet as in the <xsl:value-of> element.
The <xsl:template> matches in all cases, using prefixes.
My question is: Did I hit a bug in Xalan, or am I doing something generally wrong?
I'm aware of the various work-arounds concerning namespace prefixes, like using [local-name() = 'element'] and such, so please don't post answers in that vein. I'm looking for a general answer whether this should work (like, according to the specs).
Background Material
Stacktrace (part.) that hints at Xalan:
...
Caused by: javax.xml.transform.TransformerException: java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 512
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:783)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:370)
at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:201)
at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:870)
... 126 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 512
at java.xml/com.sun.org.apache.xml.internal.utils.SuballocatedIntVector.elementAt(SuballocatedIntVector.java:441)
at java.xml/com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase._firstch(DTMDefaultBase.java:523)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl.access$200(SAXImpl.java:73)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl$NamespaceChildrenIterator.next(SAXImpl.java:1431)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.dom.CurrentNodeListIterator.setStartNode(CurrentNodeListIterator.java:158)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator.setStartNode(StepIterator.java:97)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator.setStartNode(StepIterator.java:97)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.dom.DupFilterIterator.setStartNode(DupFilterIterator.java:97)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.dom.CachedNodeListIterator.setStartNode(CachedNodeListIterator.java:57)
at jdk.translet/die.verwandlung.test.topLevel()
at jdk.translet/die.verwandlung.test.transform()
at java.xml/com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet.transform(AbstractTranslet.java:624)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:776)
... 129 more
Invokation is through Gradle via shell command gradlew mytask using the Gradle built-in Ant using its built-in ant.xslt task.
build.gradle:
tasks.register('mytask') {
doLast {
ant.xslt(
baseDir: '.',
in: 'input.xsd',
out: 'out.xml',
style: 'stylefile.xsl'
)
}
}
Your xslt/xml code is fine (works with Saxon). So it's either something in the way you're running the transformation, or it's a bug in the version of Xalan that you're using.
Xalan shouldn't be throwing an ArrayIndexOutOfBounds exception anyway. It's presumably Xalan code on the stack trace?

XPath JMeter Assertion : Error "prefix must resolve to a namespace"

I am trying to use JMeter XPath Assertion on a tag value as below with XPath assertion command:
//m:CurrencyNameResul/text() = Pounds
Webservice Response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<m:CurrencyNameResponse xmlns:m="http://www.oorsprong.org/websamples.countryinfo">
<m:CurrencyNameResult>Pounds</m:CurrencyNameResult>
</m:CurrencyNameResponse>
</soap:Body>
</soap:Envelope>
I am getting error
prefix must resolve to a namespace
and after referring to JMeter manual below:
NAMESPACES As a work-round for namespace limitations of the Xalan XPath parser implementation on which JMeter is based, you can provide a Properties file which contains mappings for the namespace prefixes:
prefix1=Full Namespace 1
prefix2=Full Namespace 2
…
You reference this file in jmeter.properties file using the property:
xpath.namespace.config
I don't get it, so my questions are:
what should be the content of Properties file?
where to put its path?
Here is how to proceed:
Create in jmeter/bin folder a file named namespaces.properties containing:
m=http://www.oorsprong.org/websamples.countryinfo
In user.properties set:
xpath.namespace.config=namespaces.properties
Finally fix your assertion to contain:
//m:CurrencyNameResult = 'Pounds'
And check "Use Namespaces"
To end up with:
You can amend your XPath query to use name() function like:
(//*[name() = 'm:CurrencyNameResult'])/text()
and you will not have to mess up with amending properties, restarting JMeter, etc.
Moreover if you go for local-name() function instead you will not have to include the namespace prefix into your query:
(//*[local-name() = 'CurrencyNameResult'])/text()
More information:
XPath language specification
Using the XPath Extractor in JMeter
XPath Tutorial

How to turn a file into a Nokogiri::XML object?

I have a sample XML file (let's call it example.xml for the sake of this question) and want to turn it into a Nokogiri object.
According to documentation and lots of other online sources, this should work:
xml = Nokogiri::XML(File.read("example.txt"))
But the value of xml.to_xml is only:
"<?xml version=\"1.0\"?>\n"
In other words, it's ignoring the rest of the file. There are many tags afterwards and none of them are in the xml object.
How do I get Nokogiri to get all the tags?
Here's the XML I'm using:
<? xml version="1.0" encoding="UTF-8" ?>
<Document>
<Test>Test</Test>
</Document>
It looks like you are trying to parse an invalid XML doc.
This can be fixed by removing the spaces in the XML declaration:
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<Test>Test</Test>
</Document>
How I figured this out
By default, when Nokogiri has errors parsing a document it populates an errors array.
xml = Nokogiri::XML(File.read("example.txt"))
p xml.errors
# => [#<Nokogiri::XML::SyntaxError: xmlParsePI : no target name>, #<Nokogiri::XML::SyntaxError: Start tag expected, '<' not found>]
You can also configure Nokogiri to raise an exception of it has parsing errors:
xml = Nokogiri::XML(File.read("example.txt")) do |config|
config.strict
end
Both of these cases show that there were issues parsing the document

Swagger UI REST URL suffix (.json) 404 error

I have deployed a test Grape REST API and I am trying to test it with Swagger UI.
The problem is that when Swagger UI loads the API specification it adds parenthesis to the suffix: http://arcane-shore-2642.herokuapp.com/api/v1/todos(.json)
This causes a 404 error since (.json) suffix is not valid.
The URL it calls should look like this: http://arcane-shore-2642.herokuapp.com/api/v1/todos
Or this: http://arcane-shore-2642.herokuapp.com/api/v1/todos.json
How can I fix this?
My Swagger UI installation
More valid routes:
http://arcane-shore-2642.herokuapp.com/api/v1/todos/1
http://arcane-shore-2642.herokuapp.com/api/v1/items/1
http://arcane-shore-2642.herokuapp.com/api/v1/todos/1/items
http://arcane-shore-2642.herokuapp.com/api/v1/todos/1.json
http://arcane-shore-2642.herokuapp.com/api/v1/items/1.json
http://arcane-shore-2642.herokuapp.com/api/v1/todos/1/items.json
I have encountered the same problem today. It's because original API spec data came from grape-swagger gem has the "(.json)" (or format) suffix.
{
apiVersion: "0.1",
swaggerVersion: "1.2",
resourcePath: "/hotels",
produces: [
"application/json"
],
apis: [
{
path: "/hotels.{format}",
operations: [
...
There's a configuration setting hide_format to the add_swagger_documentation which can hide the format suffix. However, option hide_format still has issue in latest released version of grape-swagger (0.10.1) with latest grape (0.12.0).
So we need to specify the developing grape-swagger and then set hide_format.
Gemfile
gem 'grape-swagger', github: "tim-vandecasteele/grape-swagger"
Your root API
add_swagger_documentation hide_format: true

Cerberus API access with ruby/savon

Guys I have got an issue with wsdl processing.
Cerberus FTP server has it's own wsdl API for server configuration
www.cerberusftp.com/support/help/webservices.htm
I tried to execute some functions with ruby and savon like this:
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'savon'
client = Savon.client(wsdl: "http://192.168.1.5:10001/wsdl/Cerberus.wsdl")
response = client.call(:server_information) do
message credentials: {user: "admin", password: "123"}
end
From sniffer I can see POST request
<?xml version="1.0" encoding="UTF-8" ?>
- <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://cerberusllc.com/service/cerberusftpservice" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
- <env:Body>
- <tns:ServerInformationRequest>
- <tns:credentials>
<tns:user>admin</tns:user>
<tns:password>123</tns:password>
</tns:credentials>
</tns:ServerInformationRequest>
</env:Body>
</env:Envelope>
Also I tried tool Membarene SOAP client
<s12:Envelope xmlns:s12='http://www.w3.org/2003/05/soap-envelope'>
<s12:Body>
<ns1:ServerInformationRequest xmlns:ns1='http://cerberusllc.com/service/cerberusftpservice'>
<ns1:credentials xmlns:ns1='http://cerberusllc.com/common'>
<ns1:user>admin</ns1:user>
<ns1:password>123</ns1:password>
</ns1:credentials>
</ns1:ServerInformationRequest>
</s12:Body>
</s12:Envelope>
It's POST request slightly different and it works.
Any idea how to do the same in ruby + savon ?
I've resolved that issue.
I generate XML query manually.
it looks like:
client = Savon.client(wsdl: "http://example.com:10001/wsdl/Cerberus.wsdl")
variable = client.call(:add_group xml: "your xml " ) # you can generate this xml via SoapUI tool or Membarene SOAP client.
My standard response:
download SoapUI
build a valid, successful call
rebuild in Ruby with Savon (not RoR)
ask questions here and you will receive help :-)

Resources