I have the following xml file:
<?xml version='1.0' encoding='UTF-8'?>
<sparql xmlns='http://www.w3.org/2005/sparql-results#'>
<head>
<variable name='s'/>
</head>
<results>
<result>
<binding name='s'>
<uri>http://data.open.ac.uk/podcast/c9ddc42f6e1db95f59c83312d62da0ee</uri>
</binding>
</result>
<result>
<binding name='s'>
<uri>http://data.open.ac.uk/podcast/18873effb6c38ed83a7522ffb7c61c1b</uri>
</binding>
</result>
</results>
</sparql>
I want to get the uris from the document. I tried these commands:
doc = Nokogiri::XML(File.open("file.xml"))
doc.xpath("//uri")
but it returns nil.
However, if I modified the file to this:
<results>
<result>
<binding name='s'>
<uri>http://data.open.ac.uk/podcast/c9ddc42f6e1db95f59c83312d62da0ee</uri>
</binding>
</result>
<result>
<binding name='s'>
<uri>http://data.open.ac.uk/podcast/18873effb6c38ed83a7522ffb7c61c1b</uri>
</binding>
</result>
</results>
The above commands return the uris correctly.
You need to specify the namespace of the element you're trying to select. In the first document this is http://www.w3.org/2005/sparql-results#, inherited from the root-node. In the second document it works, because you're removed the namespace declaration by removing that root node.
The good news is because your namespace is defined in the root node Nokogiri will automatically register it for you, and you should be able to select the <uri> elements with
doc.xpath("//xmlns:uri")
Related
I am validating the below Appointment resource (which includes a contained reference) using FHIR R4 schema and schmeatron, and I always get this error:
dom-3: If the resource is contained in another resource, it SHALL be referred to from elsewhere in the resource or SHALL refer to the containing resource.
From my knowledge the contained reference is well included and referenced, and also the Resource validates against STU 3 schema and schematron, but I am not able to validate against R4 schematron.
What I am doing wrong?
Thanks
<?xml version="1.0" encoding="UTF-8"?>
<Appointment xmlns="http://hl7.org/fhir">
<contained>
<Slot>
<id value="slot159260820191620"/>
<schedule>
<identifier>
<system value="urn:oid:2.16.840.1.113883.3.7482.1.6"/>
<value value="159"/>
</identifier>
</schedule>
<status value="free"/>
<start value="2019-08-26T16:20:00+02:00"/>
<end value="2019-08-26T16:40:00+02:00"/>
</Slot>
</contained>
<status value="proposed"/>
<slot>
<reference value="#slot159260820191620"/>
</slot>
<participant>
<actor>
<identifier>
<system value="urn:oid:2.16.840.1.113883.3.7482.3.1"/>
<value value="143052"/>
</identifier>
</actor>
<status value="accepted"/>
</participant>
Nothing. The schematron is broken. It should say
...for $id in f:contained/*/f:id/#value...
I'll check to confirm whether this is in the list of technical corrections we'll be posting soon.
I want to express the following use case :
A patient is pregnant. She's seen by two specialists : an endocrinologist and an obstetric gynecologist.
The gynecologist sends her to the hospital, for a care he can't give.
The patient has then :
a family doctor
a referring doctor (obstetric gynecologist)
a specialist (endocrinologist)
The family doctor is referenced in the Patient Resource, by the generalPractitioner element.
But I want to reference the two others practitioners in the Encounter Resource.
I'm ok with the first (the referring), but I don't know where to reference the second.
<?xml version="1.0" encoding="UTF-8"?>
<Encounter xmlns="http://hl7.org/fhir">
<id value="99289910"/>
<contained>
<ReferralRequest>
<id value="p1"/>
<status value="active"/>
<category value="request"/>
<requester>
<reference value="Practitioner/99003499686"/>
<identifier>
<type>
<coding>
<system value="http://hl7.org/fhir/v2/0443"/>
<code value="RP"/>
<display value="Referring Provider"/>
</coding>
<text value="Referring doctor"/>
</type>
<system value='urn:oid:1.2.250.1.71.4.2.1'></system>
<value value='99003499686'/>
<assigner><display value="RPPS"/></assigner>
</identifier>
</requester>
</ReferralRequest>
</contained>
<status value="finished"/>
<class>
<system value="http://hl7.org/fhir/v3/ActCode"/>
<code value="IMP"/>
</class>
<patient>
<reference value="/patient/3803218"/>
</patient>
<incomingReferral>
<reference value="#p1"/>
</incomingReferral>
<period>
<start value="2016-09-07T15:39:00"/>
<end value="2016-09-11T16:35:00"/>
</period>
<location>
<location>
<reference value="/uf/1835"/>
</location>
<status value="completed"/>
<period>
<start value="2016-09-07T15:39:00"/>
<end value="2016-09-08T00:28:00"/>
</period>
</location>
<location>
<location>
<reference value="/uf/3650"/>
</location>
<status value="completed"/>
<period>
<start value="2016-09-08T00:28:00"/>
<end value="2016-09-11T16:35:00"/>
</period>
</location>
<serviceProvider>
<reference value="/uf/2407"/>
</serviceProvider>
</Encounter>
Where can I reference the specialist (endocrinologist) in the Encounter ?
If I understand correctly, the first would be identified as the referring practitioner, but the other is essentially just an "interested party" - someone who should be notified of the admission, the discharge and presumably should receive a copy of the discharge summary.
The concept of "interested party" isn't part of the value set for Encounter.participant.type, but the value set is extensible, so you're free to define your own code for that concept. It seems like a generally useful idea, so I'd encourage you to submit a change request (propose a change link at the bottom of each page in the spec) for us to add that to the specification for everyone.
3rd Party API had the following response created for my JAX-RS request:
<?xml version="1.0"?>
<name xmlns="http://www.example.com/name">
<first>John</first>
<middle>M</middle>
<last>Doe</last>
</name>
referring to this schema:
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:target="http://www.example.com/name"
targetNamespace="http://www.example.com/name" elementFormDefault="qualified">
<element name="name">
<complexType>
<sequence>
<element name="first" type="string"/>
<element name="middle" type="string"/>
<element name="last" type="string"/>
</sequence>
</complexType>
</element>
</schema>
However , they changed the server response to this by mistake:
<?xml version="1.0"?>
<ns2:name xmlns:ns2="http://www.example.com/name">
<first>John</first>
<middle>M</middle>
<last>Doe</last>
</ns2:name>
Now when I call the API using JAX-RS webclient, I have NOT null Response object , but the value inside it is all null as the child nodes of the XML response is not using namespace ns2.
How do I ignore namespace ns2? so the response object value will not be null.
I receive a large XML file and often the XML file do not validate to schema file.
Instead of droping the whole xml file I would like to remove the "invalid" content and save the rest of the XML file.
I'm using xmllint to validate the xml by this command:
xmllint -schema testSchedule.xsd testXML.xml
The XSD file (in this example named testSchedule.xsd):
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.testing.dk" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MasterData">
<xs:complexType>
<xs:sequence>
<xs:element name="Items">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:integer" name="Id" minOccurs="1"/>
<xs:element type="xs:integer" name="Width" minOccurs="1"/>
<xs:element type="xs:integer" name="Height" minOccurs="0"/>
<xs:element type="xs:string" name="Remark"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And the XML file (In this example named testXML.xml):
<?xml version="1.0" encoding="ISO-8859-1" ?>
<MasterData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.testing.dk">
<Items>
<Item>
<Id>1</Id>
<Width>10</Width>
<Height>100</Height>
<Remark>This is OK</Remark>
</Item>
<Item>
<Id>2</Id>
<Width>20</Width>
<Height>200</Height>
<Remark>This is OK - But is missing Height a non mandatory field</Remark>
</Item>
<Item>
<Id>3</Id>
<Height>300</Height>
<Remark>This is NOT OK - Missing the mandatory Width</Remark>
</Item>
<Item>
<Id>4</Id>
<Width>TheIsAString</Width>
<Height>200</Height>
<Remark>This is NOT OK - Width is not an integer but a string</Remark>
</Item>
<Item>
<Id>5</Id>
<Width>50</Width>
<Height>500</Height>
<Remark>This is OK and the last</Remark>
</Item>
</Items>
</MasterData>
Then I get the this result of the xmllint command:
testXML.xml:18: element Height: Schemas validity error : Element '{http://www.testing.dk}Height': This element is not expected. Expected is ( {http://www.testing.dk}Width ).
testXML.xml:23: element Width: Schemas validity error : Element '{http://www.testing.dk}Width': 'TheIsAString' is not a valid value of the atomic type 'xs:integer'.
testXML.xml fails to validate
And that is all correct - There is two errors in the XML file.
Now I would like to have a tool of some kind to remove entry 3 and 4 so I end up with this result:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<MasterData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.testing.dk">
<Items>
<Item>
<Id>1</Id>
<Width>10</Width>
<Height>100</Height>
<Remark>This is OK</Remark>
</Item>
<Item>
<Id>2</Id>
<Width>20</Width>
<Height>200</Height>
<Remark>This is OK - But is missing Height a non mandatory field</Remark>
</Item>
<Item>
<Id>5</Id>
<Width>50</Width>
<Height>500</Height>
<Remark>This is OK and the last</Remark>
</Item>
</Items>
</MasterData>
Does anybody in here have a tool that can do this?
I'm currently using bash scripting and the xmllint.
I really hope somebody can help.
You can achieve that with this XSLT stylesheet, which you can run in any environment which supports XSLT 1.0 (most languages), using an command line tool such as xsltproc (libxslt) or Saxon, a browser or an online tool. Here is an example.
If you feed your original XML file as input to a XSLT transformer with the following stylesheet it will produce the result you have shown in your second XML:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:t="http://www.testing.dk">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="t:Item[t:Id and not(number(t:Id))]"/>
<xsl:template match="t:Item[t:Width and not(number(t:Width))]"/>
<xsl:template match="t:Item[t:Height and not(number(t:Height))]"/>
<xsl:template match="t:Item[not(t:Width)]"/>
<xsl:template match="t:Item[not(t:Id)]"/>
<xsl:template match="t:Item[not(t:Remark)]"/>
</xsl:stylesheet>
The first <xsl:template> block simply copies all nodes from the source tree to the result tree. It has lower precedence than the specific templates which match nodes by their name.
Since matches are done in XPath which requires namespace-qualified selectors, your default namespace was declared in the <xsl:stylesheet> opening tag and mapped to a prefix that was used to qualify the tag names.
Each template uses an XPath expression to test if a specific child element is present or not in Item, or if that child is present, if it is a number (according to the XSD).
I'm using XSLT 1.0, which is more widely supported and should be easier to find in your environment. But if you can use a XSLT 2.0 processor, you could use XSLT 2.0 features such as support for XSD types, and instead of comparing your values to number type, you could compare them to specific types like xsd:integer.
You can verify the transformation performed on your example XML by that stylesheet in this XSLT Fiddle.
If you create a XML document containing the code above and place it in a file named stylesheet.xsl you can run the transformation using xsltproc (which probably exists in your environment) using:
xsltproc stylesheet.xsl testXML.xml > fixedXML.xml
I have a.wsdl & b.wsdl where a.wsdl imports b.wsdl.
Now I have to customize the schema inside b.wsdl using wsimport and JAXB. but using below customization is giving error that "XPath evaluation of "wsdl:definitions/wsdl:types/xsd:schema[#targetNamespace='b']" results in an empty target node
I am not able to find a way to customize the inlined schema in imported b.wsdl when generating the client code using wsimport.
<jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema[#targetNamespace='b']"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jaxb:globalBindings>
<jaxb:javaType name="java.util.Calendar" xmlType="xsd:dateTime"
parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />
</jaxb:globalBindings>
</jaxws:bindings>
A.wsdl
<definitions targetNamespace="a"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:interface="b">
<import location="b.wsdl" namespace="b"/>
<service name="Service">
<port binding="interface:Binding" name="Port">
<soap:address location="https://localhost/sdk/vpxdService" />
</port>
</service>
</definitions>
B.wsdl
<definitions targetNamespace="b"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:b="b"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<types>
<schema
targetNamespace="b"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:b="b"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<complexType name="XYZ">
<sequence>
<element name="dynamicType" type="xsd:string" minOccurs="0" />
<element name="val" type="xsd:anyType" maxOccurs="unbounded" />
</sequence>
</complexType>
</types>
</schema>
</definitions>
After going through given website I modified the external binding file to use wsdlLocation="b.wsdl" instead of node="wsdl:definitions/wsdl:types/xsd:schema[#targetNamespace='b']" which did the magic.
This will make sure that the inline schema defined in WSDL will customized as required.
<bindings
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl"
version="2.0">
<bindings wsdlLocation="b.wsdl">
<globalBindings>
<javaType name="java.util.Calendar" xmlType="xsd:dateTime"
parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
printMethod="javax.xml.bind.DatatypeConverter.printDate"
/>
</globalBindings>
</bindings>
</bindings>
http://fusesource.com/docs/framework/2.1/jaxws/JAXWSCustomTypeMappingOverview.html
Have you tried adding the following attributes to the <jaxws:bindings> element?
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
and
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
You're referencing the xsd and wsdl namespaces in your xpath expression, but until you define the URI's for them, they won't match up with the URI's in the target documents.