I have the below json , how can it be represented in XSD. It is a json tuple i could not find a valid construct in XSD to represent this type of json structure.
{
"type": "array",
"items": [
{
"type": "number"
},
{
"type": "string"
},
{
"type": "string",
"enum": ["Street", "Avenue", "Boulevard"]
},
{
"type": "string",
"enum": ["NW", "NE", "SW", "SE"]
}
]
}
It would help others if you would provide more context to your question. First, your example is from page 30 (print version) of the Understanding JSON Schema guide. Your JSON is a JSON schema (draft #4).
Because you're talking about schemas, I take your question as being about models. To be even clearer, I consider your question similar to one asked many years back: can one use UML to represent an XSD structure?
I actually do use XSD to describe JSON structures; we have an automatic conversion between XSD and JSON schemas (draft #4), since I use myself XSD as a data modeling language.
Your particular example has no natural XSD equivalent. By natural, I mean one that would make sense as XML as well, and which a "generic" XML-to-JSON transformation would yield an expected result.
If we take away simple things, such as a simple type modeled as a list:
<xsd:simpleType name="array">
<xsd:list itemType="xsd:float"/>
</xsd:simpleType>
which basically is the same as (except for the comma separator):
{
"type": "array",
"items": {
"type": "number"
}
}
then my answer is really about a "profile" that will be used by a conversion tool to take the semantics of a model represented in XSD (in other words, we're not hung up on XML documents here), into the same represented using JSON schema.
Our XSD-to-JSON schema profile uses a complex type to represent objects and arrays. When the "stereotype" applied to a complex type is "array", then the following model perfectly matches your JSON schema.
<xsd:complexType name="address">
<xsd:annotation>
<xsd:appinfo>
<xsd2json:type>array</xsd2json:type>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="StreetNumber" type="xsd:float"/>
<xsd:element name="StreetName" type="xsd:string"/>
<xsd:element name="StreetType">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Street"/>
<xsd:enumeration value="Avenue"/>
<xsd:enumeration value="Boulevard"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="StreetDirection">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="NW"/>
<xsd:enumeration value="NE"/>
<xsd:enumeration value="SW"/>
<xsd:enumeration value="SE"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
Related
I am pretty new to working with XML/XSD schemas etc. I am trying to use SQLXMLBulkLoad to load an XML file into SQL Server (the file to upload is greater than 2gb) and am having a problem as the source data has element names that contain hyphens, e.g. "first-name" or "start-date".
I have managed to get a few sample records imported into the database excluding those fields, but as soon as I add in any of the elements with a hyphen in the name, the import fails with an error message saying:
Schema: Invalid Value for 'column', Code: 80004005 Source: Schema Mapping
This only happens when there is a hyphen in an element name and I have no idea how to get around it. I have tried searching for the answer but can't find any reference to the issue I'm having.
The schema code is shown below:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="jobs" sql:is-constant="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="job" sql:relation="mytemptable" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:string" />
<xsd:element name="title" type="xsd:string" />
<xsd:element name="description" type="xsd:string" />
<xsd:element name="town" type="xsd:string" />
<xsd:element name="start-date" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
I am unable to get the source data file amended to exclude the hyphens so I have to find a way to handle it in the import routine, but I am still not able to get it to work.
I tried working with the OWL2-RL rules build into graphdb. I am obviously doing something wrong or understood something wrong. Here is my toy ontology.
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.semanticweb.org/rlehmann/ontologies/2017/10/untitled-ontology-182#"
xml:base="http://www.semanticweb.org/rlehmann/ontologies/2017/10/untitled-ontology-182"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:untitled-ontology-182="http://www.semanticweb.org/rlehmann/ontologies/2017/10/untitled-ontology-182#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:ontology="http://www.some/ontology/">
<owl:Ontology rdf:about="http://www.semanticweb.org/rlehmann/ontologies/2017/10/untitled-ontology-182"/>
<!-- http://www.some/ontology/hasValue -->
<owl:DatatypeProperty rdf:about="http://www.some/ontology/hasValue">
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
</owl:DatatypeProperty>
<!-- http://www.some/ontology/ClassA -->
<owl:Class rdf:about="http://www.some/ontology/ClassA"/>
<!-- http://www.some/ontology/InvA -->
<owl:NamedIndividual rdf:about="http://www.some/ontology/InvA">
<rdf:type rdf:resource="http://www.some/ontology/ClassA"/>
<ontology:hasValue rdf:datatype="http://www.w3.org/2001/XMLSchema#string">StringValue</ontology:hasValue>
</owl:NamedIndividual>
<!-- http://www.some/ontology/InvB -->
<owl:NamedIndividual rdf:about="http://www.some/ontology/InvB">
<ontology:hasValue rdf:datatype="http://www.w3.org/2001/XMLSchema#string">FooBar</ontology:hasValue>
</owl:NamedIndividual>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.some/ontology/hasValue"/>
<owl:someValuesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdfs:subClassOf rdf:resource="http://www.some/ontology/ClassA"/>
</owl:Restriction>
</rdf:RDF>
If I did not misunderstand Table 2 in OWL2-Profiles this ontology should be in OWL2 RL profile. I would expect "InvB" to be classified as type ClassA. But it doesn't. It actually does with reasoners (HermiT, Pellet, ...) but not with Rules (Drools, Graphdb) is this a gap in the specification.
How can my Ontology be "repaired" or is there any workaround?
Cheers,
Robert
Not using anonymous classes on the left-hand side of the GCI is not an option for our application. And yes object properties work perfectly.
After some research we actually found out, that it can never work that way. In the GraphDB .pie file that corresponds to the RL-Profile there is only a notion to some rules "// These are not implemented (and probably not implementable)". This includes the rule "dt-type2" defined in OWL2 RL Section 4.3 Table 8. RDF section 3.1 gives the actual answer why this is not supposed to work.
RDF Graphs
An RDF graph is a set of RDF triples.
3.1 Triples
An RDF triple consists of three components:
the subject, which is an IRI or a blank node
the predicate, which is an IRI
the object, which is an IRI, a literal or a blank node
"FooBar"^^xsd:string rdf:type xsd:string this is simply not allowed but obviously required.
We are quite uncertain what the guys at w3c had in mind besides RDF?!
As it is now, this kind of inference will not work in GraphDB at all (and on no rule engines in general?). But it is not the fault of GraphDB but merely a gap in the specification chain.
However, we did a workaround in our ontology that solves the problem and is working for us. We simply
defined new concepts for the data types we use
Transformed all DataProperties to ObjectProperties
introduces new DataType properties with domain one of the new datatype concepts and range xsd:xyz. For example Property:hasStringValue Domain:string Range:xsd:string
This works for us.
I'm attempting to import a tcx file from Garmin connect into SQL Server with SSIS. Unfortunately, I'm at a complete loss as to how I would create an xsd in order to import the datapoints I want. The Garmin XSD is http://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd. And the parts I'm concerned about are only the elements here:
<xsd:complexType name="Trackpoint_t">
<xsd:sequence>
<xsd:element type="xsd:dateTime" name="Time"/>
<xsd:element type="Position_t" name="Position" minOccurs="0"/>
<xsd:element type="xsd:double" name="AltitudeMeters" minOccurs="0"/>
<xsd:element type="xsd:double" name="DistanceMeters" minOccurs="0"/>
<xsd:element type="HeartRateInBeatsPerMinute_t" name="HeartRateBpm" minOccurs="0"/>
<xsd:element type="CadenceValue_t" name="Cadence" minOccurs="0"/>
<xsd:element type="SensorState_t" name="SensorState" minOccurs="0"/>
<xsd:element type="Extensions_t" name="Extensions" minOccurs="0">
<xsd:annotation>
</xsd:element>
</xsd:sequence>
Any pointers on how to create the xsd would be helpful. Thanks
If you would like to import part of XML file without modifications, you do not have to design your own xsd. All you need to do is:
Take XSD file from Garmit (presuming it is valid and aligns with your data) and your XML file
In SSIS package, add dataflow task, XML source in it, select your XML file as source and Garmin XSD file as schema file
Alternatively, you can try this, XML Source can design (guess) XSD from XML provided. I would recommend this only as a starting point, since guessed XSD is very approximate and based only on the sample provided; it can misinterpret node and attribute types based on the sample.
XML Source usually produce multitude of outputs, so you have to check with data viewer which one contains data you need.
After playing with this prototype, you can transform package to your needs.
You did not provide your XML-file... But I found one sample of a TCX-file here and another one here. Reading this does not need a schema. I hope, that you can solve your problems, when you see the following example:
DECLARE #xml XML=
N'<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd">
<Activities>
<Activity Sport="Running">
<Id>2015-01-25T12:14:34Z</Id>
<Lap StartTime="2015-01-25T12:14:34Z">
<TotalTimeSeconds>507.0989990</TotalTimeSeconds>
<DistanceMeters>1000.0000000</DistanceMeters>
<MaximumSpeed>2.5790000</MaximumSpeed>
<Calories>95</Calories>
<AverageHeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<Value>155</Value>
</AverageHeartRateBpm>
<MaximumHeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<Value>173</Value>
</MaximumHeartRateBpm>
<Intensity>Resting</Intensity>
<TriggerMethod>Distance</TriggerMethod>
<Track>
<Trackpoint>
<Time>2015-01-25T12:14:34Z</Time>
<Position>
<LatitudeDegrees>50.8918607</LatitudeDegrees>
<LongitudeDegrees>16.7403161</LongitudeDegrees>
</Position>
<AltitudeMeters>233.1999969</AltitudeMeters>
<DistanceMeters>0.0000000</DistanceMeters>
<HeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<Value>88</Value>
</HeartRateBpm>
<Extensions>
<TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2" CadenceSensor="Footpod">
<Speed>0.0000000</Speed>
</TPX>
</Extensions>
</Trackpoint>
</Track>
<Track />
<Extensions>
<FatCalories xmlns="http://www.garmin.com/xmlschemas/FatCalories/v1">
<Value>0</Value>
</FatCalories>
<LX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2">
<AvgSpeed>1.9720000</AvgSpeed>
</LX>
</Extensions>
</Lap>
</Activity>
</Activities>
</TrainingCenterDatabase>';
WITH XMLNAMESPACES(DEFAULT 'http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2')
select Act.value(N'#Sport','nvarchar(max)') AS Activity_Sport
,Act.value(N'(Id)[1]','datetime') AS Activity_Id
,Lap.value(N'#StartTime','datetime') AS Lap_StartTime
,Lap.value(N'(TotalTimeSeconds)[1]','decimal(20,8)') AS Lap_TotalTimeSeconds
--more fields
,Lap.value(N'(Calories)[1]','int') AS Lap_TotalTimeSeconds
,Lap.value(N'(AverageHeartRateBpm/Value)[1]','int') AS Lap_AverageHeartRateBpm
,Lap.value(N'(MaximumHeartRateBpm/Value)[1]','int') AS Lap_MaximumHeartRateBpm
,Lap.value(N'(Intensity)[1]','nvarchar(max)') AS Lap_Intensity
--more fields
,TrP.value(N'(Time)[1]','datetime') AS Track_Trackpoint_Time
,TrP.value(N'(Position/LatitudeDegrees)[1]','decimal(20,8)') AS Track_Trackpoint_Position_LatitudeDegrees
--more fields
FROM #xml.nodes(N'/TrainingCenterDatabase/Activities/Activity') AS A(Act)
OUTER APPLY Act.nodes(N'Lap') AS B(Lap)
OUTER APPLY Lap.nodes(N'Track/Trackpoint') AS C(TrP)
The result
Activity_Sport Activity_Id Lap_StartTime Lap_TotalTimeSeconds ....
Running 2015-01-25 12:14:34.000 2015-01-25 12:14:34.000 507.09899900 ....
there are some strange brain racked occurring to me.
In a given xsd file,we find a xml element that says as below:
<xsd:element name="getAllOperationsSystemsRequest">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
and a wsdl operation is linked to the element
<wsdl:operation name="getAllOperationsSystems">
<wsdl:input message="tns:getAllOperationsSystemsRequest"/>
<wsdl:output message="tns:getAllOperationsSystemsResponse"/>
<wsdl:fault name="getAllOperationsSystemsException" message="tns:getAllOperationsSystemsException"/>
</wsdl:operation>
Apparently , getAllOperationsSystemsRequest is not bound to any known type ( the attribute "type" is missing.
As the result,after we exeucte wsdl2java tool,we finally get a method definition :
public org.tmforum.mtop.mri.xsd.osr.v1.MultipleObjectsResponseType getAllOperationsSystems(
javax.xml.ws.Holder<org.tmforum.mtop.fmw.xsd.hdr.v1.Header> mtopHeader,
java.lang.**Object** mtopBody
)throws GetAllOperationsSystemsException
An Object instead of OperationsSystemsRequest is generated as the input parameter type,(actually the OperationsSystemsRequest never come into existence.
Finally ,we get a bold runtime error in marshall/unmarshall
Caused by: com.sun.istack.SAXException2: Instance of "javax.xml.bind.JAXBElement" is substituting "java.lang.Object", but "javax.xml.bind.JAXBElement" is bound to an anonymous type.
I am really appreciated anyone for information to solve it. Tnanks in advance.
Per XML Schema spec, the "type" for the getAllOperationsSystemsRequest element is an xsd:anyType. Basically, anything. That is why Object is generated in the code. The code generators generate for types, not elements (mostly). If the type is only represented in an element, then it would get an #XmlRootElement annotation, but for the most part, you have to think about the types.
I would recommend changing the schema to:
<xsd:element name="getAllOperationsSystemsRequest">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
That should generate a type and restrict the element to being an empty element.
Validation of my XML document fails on Oracle (via oraxsd c library), but succeeds in other tools.
Oracle validation error:
LSX-00009: data missing for type "#simple"
LSX-00213: only 0 occurrences of particle "sequence", minimum is 1
For following XSD:
<xs:element name="AGREE" minOccurs="0">
<xs:simpleType>
<xs:restriction base="type7434"/>
</xs:simpleType>
</xs:element>
<xs:simpleType name="type7434">
<xs:annotation>
<xs:documentation>AGREE</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:maxLength value="70"/>
</xs:restriction>
</xs:simpleType>
And following XML:
<AGREE/>
Same result for:
<AGREE></AGREE>
Is the Oracle validation wrong in this case? If so, what would be the workaround?
I have little control over XSD, some control over XML and full access to validation process itself.
Oracle version: Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit
For what it's worth, it looks like an error to me. I wonder if the validator is making some eccentric distinction between sole tags and empty elements: does it also reject <AGREE></AGREE>? Does it change the behavior if you add <xs:minLength value="0"/> to the declaration of type7434?