I'm trying to fill the autocomplete field in Orbeon (version 2016.1) with suggestions which I receive as a JSON.
The JSON I get looks like:
{"status":"success","code":200,"data":{"streets":[{"name":"Street One","id":"1"},{"name":"Street Two","id":"2"},{"name":"Street Three","id":"3"}]}}
I know that the Resource URI should point to my web service (could that URI, or the arguments I need to send, be encoded?), but I don't know how the Items, Label and Value fields should be configured in this case (the label would be name from the json and value should point to the code from the json, of course).
I referred to https://doc.orbeon.com/xforms/submission-json.html but haven't exactly managed to get what I'm trying to.
Can someone help?
Thanks in advance.
Masa
In particular, with your specific JSON, the corresponding XML will look as follows. In general, see the section Seeing the converted XML for how you can create a form in Form Builder that allows you to see what the converted XML is for any JSON.
<json type="object">
<status>success</status>
<code type="number">200</code>
<data type="object">
<streets type="array">
<_ type="object">
<name>Street One</name>
<id>1</id>
</_>
<_ type="object">
<name>Street Two</name>
<id>2</id>
</_>
<_ type="object">
<name>Street Three</name>
<id>3</id>
</_>
</streets>
</data>
</json>
Related
The Api response is {"Content":{"634331":["Product could not be found"],"634332":["Product could not be found"],"etc…
and I am having trouble to catch the values after content into xml :
<Content>
<__634331>Product could not be found</__634331>
<__634332>Product could not be found</__634332>
<__123104398>Product could not be found</__123104398>
The values are being interpreted as field names.
Is there a way to convert json object into xml array looking like:
<Content>
<res>
<key>634331</key>
<value>Product could not be found</value>
</res>
<res>
<key>634332</key>
<value>Product could not be found</value>
</res>
It's quite common in JSON for keys in a map (or "object") to represent data values rather than property names. Unfortunately this doesn't map at all well to XML, where the equivalent would usually be a structure like
<data key="__634331" value="Product could not be found"/>
No automatic converter is going to be able to recognise that this kind of conversion is appropriate.
My recommendation would be to do a custom conversion using XSLT 3.0 template rules. I would need to see more detail of your JSON and required XML to advise in more detail.
I am getting an XML with following structure
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<datym>
<bla bla>
</datym>
<datym>
<bla bla>
</datym>
</Data>
This i can successfully parsed to json and do all the work. Sometimes i am getting an empty xml with following format.
<?xml version="1.0" encoding="UTF-8"?>
<Data></data>
This however fail to parse as an xml or json using logic apps.So how do i do a validation if this is parsable XML or the empty XML? i thought of using contains() function after initiate a string but this is huge performance hit.
Thanks for your ideas.
I thought your empty xml example is till parsable. I tried to parse a xml file to a json file. This is my xml content.
<Invoices
xmlns="http://gateway.com/schemas/Invoices"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://gateway..com/schemas/Invoices Invoices.xsd">
<DocumentInfo></DocumentInfo>
<Header></Header>
<Documents></Documents>
</Invoices>
After parse, this is the json content:
{
"Invoices": {
"#xmlns": "http://gateway.com/schemas/Invoices",
"#xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"#xsi:schemaLocation":
"http://gateway..com/schemas/InvoicesInvoices.xsd",
"DocumentInfo": "",
"Header": "",
"Documents": ""
}
}
So maybe you could refer to my Logic App flow. I used a xml file as a display.
Hope this could help you, if you still have other questions, please let me know.
I actually find a way around this. So i thought i will answer my own so future others would find it useful.
My method is using XPATH.
Simply check the first node. If it returns empty array then its empty otherwise go with the normal processing.
xpath(xml(base64ToString(variables('content'))),'//datym')
or
xpath(xml(base64ToString(variables('content'))),'//datym[1]')
I want the webservice to return JSON format instead of the default XML. What should I do?
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<customers>
<customer id="1" xlink:href="http://www.mywebsite.com/api/customers/1"/>
<customer id="2" xlink:href="http://www.mywebsite.com/api/customers/2"/>
</customers>
</prestashop>
This is what I am getting when I entered http://www.mywebsite.com/api/customers in the address bar. This is XML format. I need to convert this into JSON.
It seems so late to reply this question but for others that might help.
You just need to append the param ?output_format=JSON to force Prestashop to return JSON data instead of XML by default.
E.g http://www.mywebsite.com/api/customers?output_format=JSON
This is a recurrent question. Initially Prestashop web services come with XML format. Then the JSON format was added only afterward.
I'm using the MarkLogic 7 REST API to build an AngularJS application on top of an XML document database. My documents are in NEWSML-G2 format. I've configured custom query options to return only the title and the creation date for each document that matches the search string. The problem is this.
I have a title element in my XML.
<nitf version="-//IPTC//DTD NITF 3.6//EN" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:newzmeta="http://newz.nl/metadata/" xmlns="http://iptc.org/std/NITF/2006-10-18/">
<head>
<title newz:origin="Generated" xmlns:newz="http://newz.nl/">Test Article</title>
....
</nitf>
In my custom query options, I've used the following line.
<extract-metadata>
<qname elem-ns="http://iptc.org/std/NITF/2006-10-18/" elem-name="title"/>
....
</extract-metadata>
Now, the problem is that when I hit the REST interface to make a query and ask for results in JSON format, I get the following in the response
"metadata":[{"{http://iptc.org/std/NITF/2006-10-18/}title":"Obama assumes the office of the President of the United States","metadata-type":"element"},{" {http://iptc.org/std/nar/2006-10-01/}firstCreated":"2009-01-20T05:00:09","metadata-type":"element"}]
How do I retrieve the title value on the UI side? I get a syntax error if I ask for
result.metadata.{http://iptc.org/std/NITF/2006-10-18/}title
Is there a way specifically to access this value, or to somehow change the name of the element that's returned from the MarkLogic side?
You can do this:
result.metadata.['{http://iptc.org/std/NITF/2006-10-18/}title']
The bracket notation is used to access properties whose names are not valid JavaScript identifiers, preventing you from using the dot notation.
For completeness, an alternative approach would be to write and install a transform for the search response that generates either metadata elements in the empty namespace or a JSON representation that's tuned to your requirements.
But, the simplest way is just to use the bracket notation as Dave suggests.
I'm using linq to sql and I have the need to save a few of our serializable objects to a field in our sql server database. I've defined the field as varbinary(MAX) but I'm not 100% sure that's correct. So, does anyone know how I can save an object to this field and then read it back? Thanks.
I think this depends on the format the objects are serialized in. For instance, if you are serializing out to xml then sql server (at least the latest version) supports an xml type. If you are indeed serializing out to binary, then sticking with binary is probably okay. Picking a db type that is similar to the type of the serialization will minimize a transformation bridging the db type to the object type.
I have gotten the object to serialize but I'm running into a problem getting the resulting xml saved. The object field is defined as xml so in linq to sql it's an xelement. I'm using the following code to serialize and get the xml string. But when I try to load the xml string to the xelement I get the "Illegal characters in path" error. However when I look at the generated xml I don't see any illegal characters. Here is the generated xml.
using (StringWriter sw = new StringWriter())
{
var x = new XmlSerializer(sessionObject.ObjectToStore.GetType());
x.Serialize(sw, sessionObject.ObjectToStore);
sessionRecord.sessionObject = XElement.Load(sw.ToString());
}
<?xml version="1.0" encoding="utf-16"?>
<SerializableJobSearch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Keywords>electronics</Keywords>
<StateList />
<Radius>50</Radius>
<City />
<State />
<DisciplineIdList />
<IndustryIdList />
<Direct>false</Direct>
<TempHire>false</TempHire>
<Contract>false</Contract>
<PerHour>false</PerHour>
<PerYear>false</PerYear>
<DegreeLevel />
<IncludeJobsRequiringLess>false</IncludeJobsRequiringLess>
<AddedWithin>0</AddedWithin>
<OrderBy>Rank</OrderBy>
<OrderByRank>true</OrderByRank>
<resultsPerPage>50</resultsPerPage>
<NeedToMake />
</SerializableJobSearch>