In my xsd-file I offer different date formats for the type appointment:
<xs:complexType name="appointment">
<xs:choice>
<xs:element name="jahr.Monat.Tag.Zeit" minOccurs="0" type="xs:dateTime"/>
<xs:element name="jahr.Monat.Tag" minOccurs="0" type="xs:date"/>
<xs:element name="jahr.Monat" minOccurs="0" type="xs:gYearMonth"/>
<xs:element name="jahr" minOccurs="0" type="xs:gYear"/>
</xs:choice>
</xs:complexType>
This json-object:
{
"AppointmentElementOfTypeappintment":
{
"jahr.Monat.Tag": "2002-09-24"
}
}
ends in an empty element:
<AppointmentElementOfTypeappintment/>
Only if I choose gYear I get a filled element in xml:
{
"AppointmentElementOfTypeappintment":
{
"jahr": "2002"
}
}
results in:
<AppointmentElementOfTypeappintment><jahr>2002</jahr></AppointmentElementOfTypeappintment>
My mapping object is as following:
...,
{
localName: 'appointment',
propertyInfos: [{
name: 'jahrMonatTagZeit',
elementName: 'jahr.Monat.Tag.Zeit',
typeInfo: 'DateTime'
}, {
name: 'jahrMonatTag',
elementName: 'jahr.Monat.Tag',
typeInfo: 'Date'
}, {
name: 'jahrMonat',
elementName: 'jahr.Monat',
typeInfo: 'GYearMonth'
}, {
name: 'jahr',
typeInfo: 'GYear'
}]
}, ....
Your mapping says name:'jahrMonatTag', so try:
{
"AppointmentElementOfTypeappintment":
{
"jahrMonatTag": "2002-09-24"
}
}
Update
I understand the point. However the json data that I pass to the marshaller come from an external modul i.e. I have no influence on the field names. What I do in my module is to convert these jsons into xmls. Appearently the library they use ro gather data from DB producing the jsons uses the dotted form for the fields i.e. 'jahr.Monat.Tag'.
Then you have to change property names in the mapping:
{
name: 'jahr.Monat.Tag',
elementName: 'jahr.Monat.Tag',
typeInfo: 'Date'
}
If you write your mapping manually, this is easy to do.
If you first write an XML Schema and the compile it into mappings then at the moment you'll be getting Java-style property names (jahrMonatTag vs. jahr.Monat.Tag). Jsonix Schema Compiler does not generate "original" property names at the moment, but that's an implementable feature. Please file an issue.
Disclaimer: I'm the author of Jsonix.
Related
Currently, the export-data module exports all the series data rather than processedXData and processedYData. However, I grouped the series with dataGrouping and I'd like to export only the processed data.
I'm aware that this question has been asked before (Highstock export csv based on data grouping), but it was in the context of the former export-cvs plugin.
How to modify the 'getDataRows' function in the export-data module for including only the processed data?
Example -> fiddle
Highcharts.getJSON("https://cdn.jsdelivr.net/gh/highcharts/highcharts#v7.0.0/samples/data/usdeur.json",function (data) {
var chart = Highcharts.stockChart("container", {
series: [{
name: "The series",
data: data,
dataGrouping: {
force: true,
units: [["year", [1]]]
}
}
]
});
console.log(chart.getDataRows());
}
);
in sap fiori application, search bar is working for mock data, not for backend data(sap ABAP(odata))
Filename: Master.Controller.js
onSearch : function() {
this.oInitialLoadFinishedDeferred = jQuery.Deferred();
// Add search filter
var filters = [];
var searchString = this.getView().byId("searchField").getValue();
if (searchString && searchString.length > 0) {
filters = [ new sap.ui.model.Filter("QUARTER_ID", sap.ui.model.FilterOperator.Contains, searchString) ];
}
// Update list binding
this.getView().byId("list").getBinding("items").filter(filters);
//On phone devices, there is nothing to select from the list
if (sap.ui.Device.system.phone) {
return;
}
//Wait for the list to be reloaded
this.waitForInitialListLoading(function () {
//On the empty hash select the first item
this.selectFirstItem();
});
},
filename: Master.view.xml
<subHeader id="masterSubHeader">
<Bar id="searchBar">
<contentMiddle>
<SearchField
id="searchField"
livechange= "onSearch"
width="100%">
</SearchField>
</contentMiddle>
</Bar>
</subHeader>
<content>
<List
id="list"
select="onSelect"
mode="{device>/listMode}"
noDataText="{i18n>masterListNoDataText}"
growing="true"
growingScrollToLoad="true"
items="{/quarterviewSet}">
<items
id="masterList">
<ObjectListItem
id="mainListItem"
press="onSelect"
type="{device>/listItemType}"
counter="0"
title="{QUARTER_ID}"
number="{QTRTYPE_NAME}"
numberUnit="{QUARTER_CATEGORY}"
markFavorite="false"
markFlagged="false"
showMarkers="false">
<attributes>
<ObjectAttribute id="ATTR1" text="{LOCATION}" />
<ObjectAttribute id="ATTR2" text="{CITY}" />
</attributes>
<core:ExtensionPoint
name="extListItemInfo"/>
</ObjectListItem>
</items>
</List>
</content>
You will have to figure out if the data from the backend is same as the mock data. If not, the bindings might have gone wrong. Please check if the data is loaded into the list initially with all the backend data. After that, try to do the search.
Put a break point in the onSearch function and see if the data is still there and how if the filters are created.
I'm using Microsoft's XmlLite DLL to parse a simple XML file, using the code in the example XmlLiteReader. The essential part of the code (C++) is
while(S_OK == (hr = pReader->Read(&nodeType)))
{
switch(nodeType)
{
case XmlNodeType_Element:
// Get name...
WriteAttributes(pReader, es, attributes);
break;
case XmlNodeType_EndElement:
// Process end-of-element...
break;
}
and
HRESULT WriteAttributes(IXmlReader* pReader, CString& es, StringStringMap& attributes)
{
while(TRUE)
{
// Get and store an attribute...
HRESULT hrMove = pReader->MoveToNextAttribute();
}
// ...
}
So, here's my question. With XML input such as
<?xml version="1.0" encoding="utf-8"?>
<settings version="1.2">
<runID name="test" mode="N" take_data="Y">
<cell id="01">
<channel id="A" sample="something"/>
<channel id="B" sample="something else"/>
</cell>
<cell id="03">
<channel id="A" sample="other something"/>
<channel id="B" sample="other something else"/>
</cell>
</runID>
</settings>
Everything works as expected, except that the /> at the end of each channel line, which indicates the end of the element channel, isn't recognized as the end of an element. The successive node types following channel are whitespace (\n), then element (the second channel).
How can I determine from XmlLite that element `channel' has ended? Or am I misunderstanding the XML syntax?
You can test if an element ends with /> by using the function IsElementEmpty.
I am trying to develope an Ant macrodef which gets the values separated by commas of the Require-Bundle property in a Manifest file passed as parameter. What I want to obtain is something like this:
Require-Bundle=org.eclipse.ui,org.eclipse.ui.ide,org.eclipse.ui.views...
The problem I am facing in my code is that it doesn't take into account if the property has multiple values in multiple lines, here is my code:
<macrodef name="getDependencies">
<attribute name="file" />
<attribute name="prefix" default="ant-mf." />
<sequential>
<loadproperties>
<file file="#{file}" />
<filterchain>
<linecontains>
<contains value="Require-Bundle" />
</linecontains>
<prefixlines prefix="#{prefix}" />
</filterchain>
</loadproperties>
</sequential>
</macrodef>
But this is what I get:
[echoproperties] ant-mf.Require-Bundle=org.eclipse.ui,
Any help will be appreciated.
Most likely, your Manifest file looks like this:
Require-Bundle: org.eclipse.ui,
org.eclipse.ui.ide,
org.eclipse.ui.views,
...
Unfortunately, Java Manifest files aren't quite Java Properties files. Manifest files can have attributes that span multiple lines whereas Property files can't have multi-line values. The <loadproperties> task can't handle multi-line attributes.
Instead, you'll need an Ant task that knows about Manifest files. In another question, Richard Steele provides Ant script that loads a Manifest file from a Jar file. You can adapt the example to get just the Require-Bundle attribute.
Thanks to Chad Nouis I have changed the macrodef approach to scriptdef. I have debugged and adapted the Richard Steele script to fit my needs:
<!--
Loads entries from a manifest file.
#manifest A manifest file to read
#entry The name of the manifest entry to load (optional)
#prefix A prefix to prepend (optional)
-->
<scriptdef name="getDependencies" language="javascript" description="Gets all entries or a specified one of a manifest file">
<attribute name="manifest" />
<attribute name="entry" />
<attribute name="prefix" />
<![CDATA[
var filename = attributes.get("manifest");
var entry = attributes.get("entry");
if (entry == null) {
entry = "";
}
var prefix = attributes.get("prefix");
if (prefix == null) {
prefix = "";
}
var manifest;
if (filename != null) {
manifest = new java.util.jar.Manifest(new java.io.FileInputStream(new java.io.File(filename)));
} else {
self.fail("File is required");
}
if (manifest == null) {
self.log("Problem loading the Manifest");
} else {
var attributes = manifest.getMainAttributes();
if (attributes != null) {
if (entry != "") {
project.setProperty(prefix + entry, attributes.getValue(entry));
} else {
var it = attributes.keySet().iterator();
while (it.hasNext()) {
var key = it.next();
project.setProperty(prefix + key, attributes.getValue(key));
}
}
}
}
]]>
</scriptdef>
I just spent the past couple of days digging into the messages looking for a way to pass a parameter from an URL to a XSL stylesheet.
for example, I have a current url like:
http://localhost/blocableau/data/base_bloc/blocableau3x.xml?95.2
and I want to just select the value after the ? like the 95.2 in this example, and put it in the variable var_massif.
I tried the following code with javascript for test the value substring(1) but with xsl it didn't work.
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<!-- recherche des cotations par Massif selon une variable -->
<xsl:key name="byMassif" match="bloc" use="Massif" />
<xsl:template match="BLOCS">
<script>var requete = location.search.substring(1);
mavariable=requete;alert(mavariable);x=mavariable</script>
<xsl:variable name="var_massif"><xsl:value-of select="95.2" /></xsl:variable>
<span>Ma variable xsl est : <xsl:value-of select="$var_massif"/></span>
<div style="position:relative; top:0px;left:10px;font-family: Arial, 'Helvetica Neue', 'Helvetica, sans-serif'; font-size:12px;z-index:1;">
<!-- genere un id pour chaque valeur de cotation et mise en forme -->
<xsl:for-each select="bloc[generate-id() = generate-id(key('byMassif', $var_massif)[1])]" >
<xsl:sort select="Massif" />
I assume you are loading a XML which uses a XSL processing instruction to transform the file:
<?xml-stylesheet ... ?>
You would need to read the URL and extract the query string. Unfortunately it is not automatically mapped. The only way to do that would be using document-uri(/) but it's XSLT 2.0 and not supported in browsers.
In XSLT 1.0 you would have to direct your HTTP request not to the XML file you want to process, but to a script which will load your XML and XSLT using the XSLTProcessor. Then you could pass the query-string as a parameter to the processor:
var var_massif = location.search.substring(1); // gets the string and removes the `?`
var processor = new XSLTProcessor(); // starts the XSL processor
processor.setParameter(null, "var_massif", var_massif); // sets parameter
... // load XSL, XML and transformToDocument
Inside your XSLT stylesheet you should have a global parameter variable:
<xsl:param name="var_massif" />
Which you will then be able to read with $var_massif.
UPDATE Here is a step-by-step example using JQuery:
I'm using this reduced stylesheet, just to show you how to get the parameter. It's in a file I called stylesheet.xsl:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:param name="var_massif" />
<xsl:template match="BLOCS">
<span>Ma variable xsl est : <xsl:value-of select="$var_massif" /></span>
</xsl:template>
</xsl:stylesheet>
And this input (blocableau3x.xml) in the same directory:
<BLOCS>
<bloc>
<Massif></Massif>
</bloc>
</BLOCS>
Now create this HTML file (blocableau3x.html) also in the same directory:
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.js"></script>
<script>
$( document ).ready(function() {
var var_massif = location.search.substring(1); // gets the string and removes the `?`
var body = $("body")[0]; // gets the body element where the result will be inserted
if (var_massif) {
var processor = new XSLTProcessor(); // starts the XSL processor
processor.setParameter(null, "var_massif", var_massif);
var source;
var xslReq = $.get("stylesheet.xsl", function (data) { // loads the stylesheet
processor.importStylesheet(data);
});
var xmlReq = $.get("blocableau3x.xml", function (data) { // loads the xml
source = data;
});
$.when(xslReq, xmlReq).done(function () { // waits both to load
var result = processor.transformToDocument(source); // transforms document
body.appendChild(result.documentElement); // adds result as child of body element
});
} else {
body.html("<h1>Missing query string</h1>"); // in case there is no query string
}
});
</script>
<html>
<body></body>
</html>
Instead of calling your XML file in the URL, call the HTML file. When it loads, it will load the XSL file and the XML file, and use the XSL processor to process the file. It will be able to read the query parameter and pass it as a XSL global parameter, which you can read in your XSLT file.