DocViewProperty XML Serialization - jackrabbit

DocViewProperty#format can be used to serialize a Java string to the JCR docview XML format. However, the output of that method still appears to respect carriage-return/line-feed rather than using a hex escaped control char. This means that even after I use DocViewProperty#format, I won't necessarily get the same String as what may show up in a .content.xml file in a CQ5 package -- where that whitespace is escaped. What in the serialization mechanism performs that work and how can I use that rather than rolling up a close approximation of it on my own?

Related

Sending Data in JSON schema using AT Commands

I am working on MQTT connection establishment to the server.
I need to send the data to the server in JSON schema format using AT Commands.
The module used in N58 Neoway module. Using AT Commands connection got established and for publishing data or subscribing data to/from the server, it should happen in JSON format.
The AT Command used is:
AT+MQTTPUB=1,1,<"topic_name">,<"data">
I need to send the JSON schema in the place of data.
Looking for any suggestions/help.
The source code is based on C.
The problem in sending JSON through AT commands is that it contains double quotes ", that are unfortunately interpreted according to AT commands ETSI specification as the beginning of a string parameter. So, what happens in many modules is that it is impossible so send a JSON string as a parameter.
Some modems vendors solve this issue by starting an online mode in which data can be sent rawly.
N58 uses a different strategy instead, that consists in escaping the special characters. In the AT command guide it is called data link escape.
Though the guide could be better (there's not explicit explanation of data link escape), we can infer it from the examples (see for example the one in AT+UDPSEND): in order to escape " character, just write \" as you would do in a C string. Example:
AT+MQTTPUB=1,1,"topic_name","{\"menu\":{\"id\":\"1\",\"value\":\"2\"}}"

C program to filter elements of type anyURI from string XML using XSLT

I have a XML string, I want to apply XSLT string on this XML to filter elements of type anyURI.
I am interested to use libxslt. But It transforms the xml present in file. I want to transform xml string.
How to write a C program to transform this xml string?
In terms of XSLT, libxslt is an XSLT 1.0 processor so it doesn't support W3C schema types like xs:anyURI in XSLT, you would need to use an XSLT 2 or 3 processor. Therefore I am not sure how you expect your XSLT program, whether you have it in a file or in a string, to filter out elements of type xs:anyURI.
In terms of C, I guess, depending on your "string" representation, you need to use http://www.xmlsoft.org/html/libxml-parser.html#xmlReadMemory or xmlReadDoc to get an http://www.xmlsoft.org/html/libxml-tree.html#xmlDocPtr for both the XML "string" input and the XSLT "string" input and then the libxslt APIs allow you to use http://xmlsoft.org/XSLT/html/libxslt-xsltInternals.html#xsltParseStylesheetDoc to get an xsltStylesheetPtr and then to run xsltApplyStylesheet.

Convert XML to JSON in C language [duplicate]

I've been searching to no avail for a set of routines to do conversion between JSON and XML. I have found such routines in Javascript, Java, PHP, and Python, but not in C or C++.
FWIW, my json library is json-spirit. I am currently processing JSON, and would like to add XML support via a conversion layer (convert incoming messages from XML to JSON, process them, convert results back to XML, and them out).
Does anyone have any pointers?
I've also seen a number of references to badgerfish, rayfish, rabbitfish... encoding conventions, but they seem to point to dead URLs. Is there a reference somewhere which describes each convention?
And yes, I've checked on json.org.
By far, the only specifically designed C++ library that directly converts XML to JSON I found on the Internet is xml2json: https://github.com/Cheedoong/xml2json
You can also convert JSON to XML if following the same rules.
Boost.PropertyTree handles both JSON and XML. There are some quirks in their implementations, so it wouldn't be a direct transformation, but it shouldn't need much work to adapt a property_tree between JSON and XML.
You could write a xslt for your xml document to convert to json. But I see no standard jslt for converting json.

How to load XML with special characters using XDocument.Load

**This is for silverlight application.
I have a stream with xml data, which after loading massage the data and generate final file. I start by load using XDocument.Load(stream). One of the file was failing to load and after some research I foung out that one of the element has a value of 'First & Second' and load fails on hitting &.
Is it possible to load XML with special characters? ( I am sure the answer is no, but worth asking).
Is it possible to preprocess the XML (without performance hit) and change the special characters to someother characters and after the process put it back to normal value.
In XML, & should be & otherwise it's not valid XML. If you don't have control over the XML files, load them as text, replace & with & in memory (but be careful not to replace the & that are part of entities like existing & > or < !) and load them as XML again.

How to escape special characters when retrieving data from database?

I am going to generate XML file based on the data returned from SQL Server, but there are some special characters like  and  (there may be other characters like these), which will fail the XML.
Is there any way to escape them?
Thanks!
The control characters U+001C (file separator) and U+001F (unit separator) are not legal to include in an XML 1.0 document, whether verbatim or encoded using a &#...; numeric character reference.
They are allowed in XML 1.1 documents only when included as a character reference. However, XML 1.1 is not nearly as widely accepted as 1.0, and you can't have U+0000 (null) even as a character reference, so it's still not possible to put arbitrary binary data in an XML file — not that it was ever a good idea.
If you want to include data bytes in an XML file you should generally be using an ad hoc encoding of your own that is accepted by all consumers of your particular type of document. It is common to use base64 for the purpose of putting binary data into XML. For formats that do not accommodate any such special encoding scheme, you simply cannot insert these control characters.
What is the purpose of the control characters?
The exact same way you're escaping any other user-supplied input prior to insertion into a database; probably one of (from worst to best):
Escaping control characters prior to construction of an SQL statement
Use of parameterised queries
Use of a DAO or ORM which abstracts this problem away from you
Use parametrized queries and you won't have to worry about escaping. Can't really give you more help as to how to use them unless you mention which language you're using.
Well, I just use the pattern matching stuff to replace those special characters manually. Match for '&#.+?;'

Resources