I am currently using ODI to import data that is in JSON format into an Oracle Database. I am currently using the Complex File topology, which requires me to identify the JSON file and the XSD used to translate it to XML before it maps the data into a table in the database.
I have a JSON file called sample.json:
{"DATA_DS": {"G_1": [
{
"FIELDA": "Test Data ",
"FIELDB": "12345",
"FIELDC": " ",
"FIELDD": null,
"FIELDE": " Test Data"
}
]}}
I have an XSD called sample.xsd:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://TargetNamespace.com/InboundService" xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" targetNamespace="http://TargetNamespace.com/InboundService" elementFormDefault="qualified" nxsd:version="JSON" nxsd:encoding="UTF-8">
<xsd:element name="Root-Element">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="DATA_DS">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="G_1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FIELDA" type="xsd:string"/>
<xsd:element name="FIELDB" type="xsd:string"/>
<xsd:element name="FIELDC" type="xsd:string"/>
<xsd:element name="FIELDD" type="xsd:string"/>
<xsd:element name="FIELDE" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
When trying to translate from JSON to XML, it says that it cannot normalize.
On further investigation, I noticed that the error occurs due to FIELDC having ONLY space.
I want to be able to keep everything that is inside the double quotes, including space.
I have tried changing the XSD twice, but to no avail.
Created a simpleType and changed the type of every element inside to use the new simpleType:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://TargetNamespace.com/InboundService" xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" targetNamespace="http://TargetNamespace.com/InboundService" elementFormDefault="qualified" nxsd:version="JSON" nxsd:encoding="UTF-8">
<xsd:element name="Root-Element">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="DATA_DS">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="G_1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FIELDA" type="stringspace"/>
<xsd:element name="FIELDB" type="stringspace"/>
<xsd:element name="FIELDC" type="stringspace"/>
<xsd:element name="FIELDD" type="stringspace"/>
<xsd:element name="FIELDE" type="stringspace"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="stringspace">
<xsd:restriction base="xsd:string">
<xsd:whiteSpace value="preserve" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
Created a simpleType inside each element and identify to preserve whitespace:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://TargetNamespace.com/InboundService" xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" targetNamespace="http://TargetNamespace.com/InboundService" elementFormDefault="qualified" nxsd:version="JSON" nxsd:encoding="UTF-8">
<xsd:element name="Root-Element">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="DATA_DS">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="G_1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FIELDA"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:whiteSpace value="preserve"/></xsd:restriction></xsd:simpleType></xsd:element>
<xsd:element name="FIELDB"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:whiteSpace value="preserve"/></xsd:restriction></xsd:simpleType></xsd:element>
<xsd:element name="FIELDC"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:whiteSpace value="preserve"/></xsd:restriction></xsd:simpleType></xsd:element>
<xsd:element name="FIELDD"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:whiteSpace value="preserve"/></xsd:restriction></xsd:simpleType></xsd:element>
<xsd:element name="FIELDE"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:whiteSpace value="preserve"/></xsd:restriction></xsd:simpleType></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
I am kind of new to the whole JSON,XML,XSD space, so any kind of help will be greatly appreciated.
Thanks a lot in advance! :)
You say "it says that it cannot normalize" but you don't say what "it" is.
There are many ways of converting to JSON to XML, and you haven't said which one you are using. It sounds to me as if "it" is the particular conversion tool or library that you are using, and your problem is with this tool or library.
Also, rather than paraphrasing an error message, it's best to quote it exactly. There may be people here who recognize it and can tell you exactly what it means.
Related
I am facing some issue while extracting XML value from the JSON element using XSLT in OIC, the requirement is to map those XML value to the XML element at target side by applying loop as xml value element is repeating. below are the input and output format, require your expert input-
input
{
"requestMessage":{
"contactName":"",
"primaryPhoneExt":"",
"secondaryPhoneExt":"",
"thirtyMinCallReqFlg":"<cmPCReadingDetails><readingDetailsList><readSequence>1</readSequence><readingUOM>1</readingUOM><readingTOU>1</readingTOU><readingSQI>1</readingSQI><meterRegisterTypeCode>KW</meterRegisterTypeCode><numberOfDials>6</numberOfDials><numberOfDecimals>3</numberOfDecimals><upperLimit>0</upperLimit><lowerLimit>41</lowerLimit><reading>41</reading><newReading>40</newReading><override>false</override><measurementCondition>501000</measurementCondition><measurementDescription>Regular</measurementDescription></readingDetailsList><readingDetailsList><readSequence>2</readSequence><readingUOM>1</readingUOM><readingTOU>1</readingTOU><readingSQI>1</readingSQI><meterRegisterTypeCode>KWH</meterRegisterTypeCode><numberOfDials>5</numberOfDials><numberOfDecimals>0</numberOfDecimals><upperLimit>0</upperLimit><lowerLimit>312</lowerLimit><reading>312</reading><newReading>111</newReading><override>false</override><measurementCondition>501000</measurementCondition><measurementDescription>Regular</measurementDescription></readingDetailsList></cmPCReadingDetails> ",
"contactPersonPhone":""
}
}
Target Element-:
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.org"
targetNamespace="http://www.example.org" elementFormDefault="qualified">
<xsd:element name="thirtyMinCallReqFlg">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="cmPCReadingDetails">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="readingDetailsList" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="readSequence" type="xsd:integer"/>
<xsd:element name="readingUOM" type="xsd:integer"/>
<xsd:element name="readingTOU" type="xsd:integer"/>
<xsd:element name="readingSQI" type="xsd:integer"/>
<xsd:element name="meterRegisterTypeCode" type="xsd:string"/>
<xsd:element name="numberOfDials" type="xsd:integer"/>
<xsd:element name="numberOfDecimals" type="xsd:integer"/>
<xsd:element name="upperLimit" type="xsd:integer"/>
<xsd:element name="lowerLimit" type="xsd:integer"/>
<xsd:element name="reading" type="xsd:integer"/>
<xsd:element name="newReading" type="xsd:integer"/>
<xsd:element name="override" type="xsd:string"/>
<xsd:element name="measurementCondition" type="xsd:integer"/>
<xsd:element name="measurementDescription" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
appreciate your help.
Regards,
Nilesh Jha
I am trying to combine a WMS with an external ShapeFile uploaded to my GeoServer.
I got my WMS Map working fine with a leaflet client but I have no idea how to implement my Shapefile.
I uploaded my ShapeFile on my GeoServer in the Vectordata section.
When I do the WFS DescribeFeature request I get this answer:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:Assignment11="http://localhost:8080/geoserver/Assignment11" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" targetNamespace="http://localhost:8080/geoserver/Assignment11">
<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/2.1.2/feature.xsd"/>
<xsd:complexType name="krankenhaeuserType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:PointPropertyType"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_ID" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_BEZ" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_TELEFON" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_URL" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_ART" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="TRAEGER" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="RECHTSFOR" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="BS_BEZ" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="PLZ" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="ADRESSE" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="ORT" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="DISZIPLIN" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="BETTENZAHL" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="krankenhaeuser" substitutionGroup="gml:_Feature" type="Assignment11:krankenhaeuserType"/>
</xsd:schema>
When I do the GetFeature Request with outputFormat=JSON (http://localhost:8080/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName=Assignment11:krankenhaeuser&outputFormat=JSON) the answer is a complete FeatureCollection of all my features.
The thing I am missing now is that I want to add all those Features to my map as a marker for example.
Thats the main problem.
When I got that working, I want to hide all those Features and when I click the map I want the closest Feature to pop up.
This is my code so far:
<!DOCTYPE html>
<html>
<head>
<title>Assignment 11</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/leaflet#1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet#1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
</head>
<body>
<div id="mapid" style="width: 1400px; height: 700px;"></div>
<script>
var mymap = L.map('mapid').setView([51.28, 7.33], 8);
var nrwTopo = L.tileLayer.wms('http://www.wms.nrw.de/geobasis/wms_nw_dtk?', {
layers: 'WMS_NW_DTK',
format: 'image/png',
transparent: true
}).addTo(mymap);
</script>
</body>
</html>
I am trying to use servicestack as a datasource for my SSRS report. Is this possible? Right now I have a simple operation that takes a date as a parameter, looks like this in C#
[DataContract]
[Route("/Reports/SummaryBySymbol/{SummaryDate}", Summary = "Summarizes trades by symbol for a specific date.")]
public class GetTradesGroupedBySymbol : IReturn<TradesGroupedBySymbolResponse>
{
[DataMember]
[ApiMember(Name = "Summary Date",
Description = "The date for which the trades will be summarized..",
DataType = "DateTime",
IsRequired = true)]
public DateTime SummaryDate { get; set; }
}
[DataContract]
public class TradesGroupedBySymbolResponse
{
[DataMember] public IList<SymbolSummary> Result { get; set; }
}
I am trying to create a dataset in SSRS using: http://machineName:port/soap11
as the datasource.
When the dataset asks for a query, I have no idea what to enter as text and the examples I can find always cause the interface to freeze when I hit the 'next' button (so I must assume I entered something incorrectly).
Here is what I tried to enter as the query:
<Query>
<Method Namespace="http://www.company.com/types" Name="GetTradesGroupedBySymbol" />
<SoapAction>
http://www.company.com/types/GetTradesGroupedBySymbol
</SoapAction>
<Parameters>
<Parameter Name="SummaryDate" Type="XML"/>
</Parameters>
<ElementPath IgnoreNamespaces="True">
GetTradesGroupedBySymbolResponse{}/Result{}/SymbolSummary
</ElementPath>
</Query>
Here is the wsdl for the service:
<wsdl:definitions xmlns:svc="http://www.company.com/types" xmlns:tns="http://www.company.com/types" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" name="Soap11" targetNamespace="http://www.company.com/types">
<wsdl:types>
<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType"/>
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/>
<xs:element name="boolean" nillable="true" type="xs:boolean"/>
<xs:element name="byte" nillable="true" type="xs:byte"/>
<xs:element name="dateTime" nillable="true" type="xs:dateTime"/>
<xs:element name="decimal" nillable="true" type="xs:decimal"/>
<xs:element name="double" nillable="true" type="xs:double"/>
<xs:element name="float" nillable="true" type="xs:float"/>
<xs:element name="int" nillable="true" type="xs:int"/>
<xs:element name="long" nillable="true" type="xs:long"/>
<xs:element name="QName" nillable="true" type="xs:QName"/>
<xs:element name="short" nillable="true" type="xs:short"/>
<xs:element name="string" nillable="true" type="xs:string"/>
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/>
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/>
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/>
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/>
<xs:element name="char" nillable="true" type="tns:char"/>
<xs:simpleType name="char">
<xs:restriction base="xs:int"/>
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration"/>
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
<xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
<xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid"/>
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName"/>
<xs:attribute name="Id" type="xs:ID"/>
<xs:attribute name="Ref" type="xs:IDREF"/>
</xs:schema>
<xs:schema xmlns:tns="http://www.company.com/types" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.company.com/types">
<xs:complexType name="GetTradesGroupedBySymbol">
<xs:sequence>
<xs:element minOccurs="0" name="SummaryDate" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
<xs:element name="GetTradesGroupedBySymbol" nillable="true" type="tns:GetTradesGroupedBySymbol"/>
<xs:complexType name="GetTradesGroupedBySymbolResponse">
<xs:sequence>
<xs:element minOccurs="0" name="Result" nillable="true" type="tns:ArrayOfSymbolSummary"/>
</xs:sequence>
</xs:complexType>
<xs:element name="GetTradesGroupedBySymbolResponse" nillable="true" type="tns:GetTradesGroupedBySymbolResponse"/>
<xs:complexType name="ArrayOfSymbolSummary">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="SymbolSummary" nillable="true" type="tns:SymbolSummary"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfSymbolSummary" nillable="true" type="tns:ArrayOfSymbolSummary"/>
<xs:complexType name="SymbolSummary">
<xs:sequence>
<xs:element minOccurs="0" name="BuyQuantityFilled" type="xs:int"/>
<xs:element minOccurs="0" name="BuyTotalValue" type="xs:double"/>
<xs:element minOccurs="0" name="BuyWeightedAveragePrice" type="xs:double"/>
<xs:element minOccurs="0" name="CompanyName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="SellQuantityFilled" type="xs:int"/>
<xs:element minOccurs="0" name="SellTotalValue" type="xs:double"/>
<xs:element minOccurs="0" name="SellWeightedAveragePrice" type="xs:double"/>
<xs:element minOccurs="0" name="Ticker" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="SymbolSummary" nillable="true" type="tns:SymbolSummary"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetTradesGroupedBySymbolIn">
<wsdl:part name="par" element="tns:GetTradesGroupedBySymbol"/>
</wsdl:message>
<wsdl:message name="GetTradesGroupedBySymbolOut">
<wsdl:part name="par" element="tns:GetTradesGroupedBySymbolResponse"/>
</wsdl:message>
<wsdl:portType name="ISyncReply">
<wsdl:operation name="GetTradesGroupedBySymbol">
<wsdl:input message="svc:GetTradesGroupedBySymbolIn"/>
<wsdl:output message="svc:GetTradesGroupedBySymbolOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_ISyncReply" type="svc:ISyncReply">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetTradesGroupedBySymbol">
<soap:operation soapAction="http://www.company.com/types/GetTradesGroupedBySymbol" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SyncReply">
<wsdl:port name="BasicHttpBinding_ISyncReply" binding="svc:BasicHttpBinding_ISyncReply">
<soap:address location="http://serverName:port/soap11"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I would expect the query to ask me for a parameter before attempting to run the soapAction (or at least error out), but the interface just locks up and I have to kill Visual Studio. Any ideas out there as to what I am doing wrong?
EDIT 1
Modified the above query and wsdl to show latest attempts to get this to work. VS still freezes.
It appears that the problem was the long running webservice response causing a connection time out in the wizard and causing the entire VS2017 environment to freeze (not optimal behavior). Once I created a dummy version of the webservice that responds with the same DTO and couple of dummy rows but that returned in less than a second, everything worked. The report was generated and I could then go in to the dataset, change the timeout to be 2 minutes and then changed the query to point back to the real web method and it worked as expected.
As a follow up detail, if you are passing a date to ServiceStack, use the 'String' data type (not XML) and ensure that the date format is yyyy-mm-dd (months and days must be padded with zeros if they are single digit values).
How can I convert *.RESX XML file to JSON file in C#?
I have regular RESX file. For example:
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data xml:space="preserve" name="KEY_1">
<value>Text A</value>
</data>
<data xml:space="preserve" name="KEY_2">
<value>Text B</value>
</data>
</root>
I need to convert this file to JSON file:
{
"Texts": [
{
"id": "KEY_1",
"text": "Text A"
},
{
"id": "KEY_2",
"text": "Text B"
}
]
}
As you can see for conversion is relevant only part with data:
<data xml:space="preserve" name="KEY_1">
<value>Text A</value>
</data>
<data xml:space="preserve" name="KEY_2">
<value>Text B</value>
</data>
Everything else is irrelevant for transformation.
Name in data attribute XML => is id in JSON file.
Value in XML=> is text in JSON file.
EDIT:
I have solution, but I think that it can be done better
using System.Xml;
using System.IO;
using System.Collections.Generic;
using System.Linq;
namespace XMLtoJSON
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, string> result = new Dictionary<string, string>();
// To convert an XML node contained in string xml into a JSON string
var xml = File.ReadAllText(#"C:\Test\ClientLocalization.en-US.resx");
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNodeList node = doc.GetElementsByTagName("data");
foreach (XmlNode item in node)
{
var value = item.InnerText.Trim();
var keyName = item.Attributes.Cast<XmlAttribute>().FirstOrDefault(f => f.Name == "name");
if (keyName != null)
{
var key = keyName.InnerText.Trim();
result.Add(key, value);
}
}
string res = #"{ ""Text"" : [ ";
foreach (var item in result)
{
res += "{";
res += $" \"id\":\"{item.Key}\",\"text\":\"{item.Value}\"";
res += "},";
}
res = res.Remove(res.Length - 1);
res += #" ]} ";
}
}
}
Instead of using XmlDocument, I would use XElement as it is much more LINQ-friendly. Use XElement.Parse to load the XML, then select the nodes you are interested in and shape them into an anonymous object structure that mirrors the JSON you want. Finally, use your favorite JSON serializer (such as Json.Net or JavaScriptSerializer) to create the JSON from there. I don't recommend hand-rolling your own JSON, as it is very error prone.
using Newtonsoft.Json;
var xml = File.ReadAllText(#"C:\Test\ClientLocalization.en-US.resx");
var obj = new
{
Texts = XElement.Parse(xml)
.Elements("data")
.Select(el => new
{
id = el.Attribute("name").Value,
text = el.Element("value").Value.Trim()
})
.ToList()
};
string json = JsonConvert.SerializeObject(obj, Newtonsoft.Json.Formatting.Indented);
// OR:
//JavaScriptSerializer jss = new JavaScriptSerializer();
//string json = jss.Serialize(obj);
Console.WriteLine(json);
Fiddle: https://dotnetfiddle.net/ZIaCjd
I'd recommend you the JSON.NET Framework.
It has built-in functions for converting XML to JSON and vice versa.
Example:
string xml = #"<?xml version='1.0' standalone='no'?>
<root>
<person id='1'>
<name>Alan</name>
<url>http://www.google.com</url>
</person>
<person id='2'>
<name>Louis</name>
<url>http://www.yahoo.com</url>
</person>
</root>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
string jsonText = JsonConvert.SerializeXmlNode(doc);
//{
// "?xml": {
// "#version": "1.0",
// "#standalone": "no"
// },
// "root": {
// "person": [
// {
// "#id": "1",
// "name": "Alan",
// "url": "http://www.google.com"
// },
// {
// "#id": "2",
// "name": "Louis",
// "url": "http://www.yahoo.com"
// }
// ]
// }
//}
I`m trying to call a Nav 2013 R2 web service codeunit with a custom SOAP command and I get a response indicating that the parameters being passed are null, which they are not.
Does anyone have an answer as to why this is happening or could point me in a direction that could help solve this? Thanks!
Here is the SOAP request:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><TransferOrderCreate xmlns="urn:microsoft-dynamics-schemas/Codeunit/WebTestCodeunit"><ptext>this is some text</ptext><pint>999</pint></TransferOrderCreate></soap:Body></soap:Envelope>
Here is the SOAP response:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="urn:microsoft-dynamics-schemas/error">a:Microsoft.Dynamics.Nav.Service.WebMetadata.ServiceBrokerException</faultcode><faultstring xml:lang="en-CA">Parameter ptext in method TransferOrderCreate in service WebTestCodeunit is null! </faultstring><detail><string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Parameter ptext in method TransferOrderCreate in service WebTestCodeunit is null! </string></detail></s:Fault></s:Body></s:Envelope>
Here is the service as exposed by Nav:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:microsoft-dynamics-schemas/codeunit/WebTestCodeunit" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/WebTestCodeunit" debug="true">
<script id="FirebugLite" firebugIgnore="true" extension="Chrome"/>
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/WebTestCodeunit">
<element name="TransferOrderCreate">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="ptext" type="string"/>
<element minOccurs="1" maxOccurs="1" name="pint" type="int"/>
</sequence>
</complexType>
</element>
<element name="TransferOrderCreate_Result">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="return_value" type="string"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="TransferOrderCreate">
<part name="parameters" element="tns:TransferOrderCreate"/>
</message>
<message name="TransferOrderCreate_Result">
<part name="parameters" element="tns:TransferOrderCreate_Result"/>
</message>
<portType name="WebTestCodeunit_Port">
<operation name="TransferOrderCreate">
<input name="TransferOrderCreate" message="tns:TransferOrderCreate"/>
<output name="TransferOrderCreate_Result" message="tns:TransferOrderCreate_Result"/>
</operation>
</portType>
<binding name="WebTestCodeunit_Binding" type="tns:WebTestCodeunit_Port">
<binding xmlns="http://schemas.xmlsoap.org/wsdl/soap/" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="TransferOrderCreate">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:microsoft-dynamics-schemas/codeunit/WebTestCodeunit:TransferOrderCreate" style="document"/>
<input name="TransferOrderCreate">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</input>
<output name="TransferOrderCreate_Result">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</output>
</operation>
</binding>
<service name="WebTestCodeunit">
<port name="WebTestCodeunit_Port" binding="tns:WebTestCodeunit_Binding">
<address xmlns="http://schemas.xmlsoap.org/wsdl/soap/" location="http://lt0619.xx.xxxxxxxxx.xx:11047/Trunk/WS/7002/Codeunit/WebTestCodeunit"/>
</port>
</service>
</definitions>
Check namespaces in wsdl definition and your request. Namespaces are case sensitive.
wsdl:
urn:microsoft-dynamics-schemas/codeunit/WebTestCodeunit
reqest:
urn:microsoft-dynamics-schemas/Codeunit/WebTestCodeunit
This could throw the exception you see.