I'm analyzing KMIP to implement a prototype in scala. I try so to understand all concepts to implement an architecture for different encoding profiles (bytes, JSON, XML).
In specification section 5.4.1.6 XML Element Encoding, it stipulates :
[...] structure values are encoded as nested xml elements, and non-structure
values are encoded using the ‘value’ attribute
With this example :
<ActivationDate type="DateTime" value="2001-01-01T10:00:00+10:00"/>
I don't understand this syntax since Activation Date is an attribute. In section 2.1.1 Attribute an attribute is described with a structure containing Attribute Name, Attribute Index, Attribute Value.
The XML representation of an ActivationDate or other attributes should be :
<Attribute>
<AttributeName type="TextString" value="Activation Date"/
<AttributeValue type="DateTime" value="2001-01-01T10:00:00+10:00"/>
</Attribute>
Moreover, the KMIP test case uses this second representation.
If the first representation is shown as an example, it will be used. So in which case ?
The KMIP specification is very vague on this point. BOTH forms of Attribute you described are considered valid KMIP and should be handled.
I strongly recommend the KMIP Additional Message Encodings document when implementing http/json/xml encoding- https://docs.oasis-open.org/kmip/kmip-addtl-msg-enc/v1.0/os/kmip-addtl-msg-enc-v1.0-os.html
section 6.1.6 describes yet another format that isn't covered in the main spec: <TTLV tag="0x420001" name="ActivationDate" type="DateTime" value="2001-01-01T10:00:00+10:00"/>
Related
When I am trying to convert XML to JSON using XSLT3
<xsl:copy-of select="xml-to-json($finalOutPut, map { 'indent' : false() })"/>
I get below error :
net.sf.saxon.s9api.SaxonApiException: xml-to-json: element found in wrong namespace: Q{}wrapper
Basically i am converting one xml to another xml , renaming certain field.
Passing this xml as a input to xml-to-json() .
Any suggestions?
The XML format that xml-to-json consumes is specified both in the XSLT 3.0 specification (https://www.w3.org/TR/xslt-30/#json-to-xml-mapping) as well as in the XPath and XQuery 3.1 function specification: https://www.w3.org/TR/xpath-functions/#json.
Basically all elements need to be in the namespace http://www.w3.org/2005/xpath-functions and are map, array, string, boolean, number etc., to reflect the JSON datatypes.
The error message suggests your input contains an element named wrapper in no namespace, so that is certainly not the right format for that function. You will need to use additional transformation steps to transform your XML to the one the function expects.
In the oneM2M HTTP protocol binding spec (TS-0009) it says:
Any of the short names listed in table 6.2.2.2-1, with the exception of ‘atr’, may be used in the query-string. The short name ‘atr’ itself is not used. Instead, any of the resource attribute short names as listed in tables 8.2.3-1 to 8.2.3-5 in oneM2M TS-0004 [3] may be used in the query-string in representations of attname=attvalue expressions...
However, there is no mention of how the key/value pairs in filterCriteria.attribute are supposed to be encoded in a CoAP request (eg, in TS-0008).
Is this specified somewhere?
"atr", ie. the resource attributes in a query, are part of the Filter Criteria (see TS-0004, section 7.3.3.17.9). Filter Criteria elements are encoded in the CoAP uri-query option (see TS-0008, the last paragraph of section "6.2.2.3 URI Options").
See also IETF RFC 7252, section 6.5, which step 8, defines how to encode key/value pairs in the uri-query option.
I will be receiving the following XML data in a variable.
<order>
<name>xyz</name>
<city>abc</city>
<string>aGVsbG8gd29ybGQgMQ==</string>
<string>aGVsbG8gd29ybGQgMg==</string>
<string>aGVsbG8gd29ybGQgMw==</string>
</order>
Output:
<order>
<name>xyz</name>
<city>abc</city>
<string>hello world 1</string>
<string>hello world 2</string>
<string>hello world 3</string>
</order>
I know how I can decode from base64 but the problem is some of the values are decoded already and some are encoded. What is the best approach to decode this data using groovy so that I get the output as shown?
Always: tag value will be encoded. rest all other tags and value will be decoded.
Since there's no uncertainty on which nodes could come encoded and which not, hence no need to detect base64 encoding, the way to do it is pretty simple:
Parse it. There's two preferable ways to do that in Groovy: XmlSlurper & XmlParser. They differ in computation & mem consumption modes, both provide object/structure representation in the end, though.
Work with that object structure: traverse all required elements, decode the content/attributes you need to decode.
Either proceed further with the data with them and/or serialize it back to the XML text.
Articles to look at:
Load, modify, and write an XML document in Groovy
https://www.baeldung.com/groovy-xml
https://groovy-lang.org/processing-xml.html
and many, many more.
Another cheat sheet always useful for Groovy noobs: http://groovy-lang.org/groovy-dev-kit.html
Check out how to traverse the structures there, for instance.
i am marshalling a pojo using jaxb.
The pojo class contains a variable of type string and the value being set contains the currency symbol in it depending on the java.util.LOCALE being passed.
My problem is while passing LOCALE.US , its working fine (eg. $235.36) but while passing any other LOCALE , say LOCALE.CHINA , a junk character is appended in front of the currency symbol (eg. ï¿¥235.36).
Any suggestions,answers and experiences related to such scenario are most welcomed. Thanks in advance.
By default a JAXB implementation will output to UTF-8. You can specify another encoding using the JAXB_ENCODING property (see: http://blog.bdoughan.com/2011/08/jaxb-and-java-io-files-streams-readers.html). Also note JAXB may be handling the character correctly but the viewer you are using to examine the XML may not.
I encountered a parsing error with Apache CXF while processing a webservice response. What it comes down to is an empty element being returned:
<myValue />
The element definition is as follows:
<xsd:element name="myValue" type="xsd:float" minOccurs="0">
Now I've read on the CXF mailing list that an empty value is not allowed by the XSD-spec:
Well, there isn't a workaround for
this as it's not a bug. An empty
element is not valid for any Decimal
or Date type or anything like that.
Thus, it SHOULD throw an exception.
What are you expecting it to do?
Now here comes the question: Where exactly can I find this constraint in the XML Schema specification?
Where exactly can I find this constraint in the XML Schema specification?
http://www.w3.org/TR/xmlschema-2/#float-lexical-representation
float values have a lexical
representation consisting of a
mantissa followed, optionally, by the
character "E" or "e", followed by an
exponent.
...
The representations for exponent and
mantissa must follow the lexical rules
for integer and decimal.
...
The special values positive and
negative infinity and not-a-number
have lexical representations INF, -INF
and NaN, respectively.
So xs:float requires at least a mantissa that is a xs:decimal...
decimal has a lexical representation
consisting of a finite-length sequence
of decimal digits (#x30-#x39)
separated by a period as a decimal
indicator. An optional leading sign is
allowed.
...and an empty string is not a valid xs:decimal.
If you don't have a value for this element, you should try not including this element, if possible. Your schema seems to allow omitting this element because minOccurs has value 0. Other solution would be to insert a suitable replacement value, like 0 or NaN.
This is not a definitive constraint.
You should be able to change your xsd to
<xsd:element name="myValue" type="xsd:float" minOccurs="0" default="0" />
And then be able to supply an empty element for your float without causing your xml to be invalid.
The above example means that if the element is empty, then its value is 0. Beware, default attribute does not apply on missing elements: missing elements are just missing, whether they have a declared default or not.
http://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints
if the element appears without any content, the schema processor provides the element with a value equal to that of the default attribute. However, if the element does not appear in the instance document, the schema processor does not provide the element at all.
I have not used this till now, but to guard against a personal miss-reading of w3c specs, I have check with an online validator that an xml with an empty xs:float element having a default was accepted (at least by this online validator: http://www.freeformatter.com/xml-validator-xsd.html ).