Repository navigation
Closed
Description
Hi
I have an issue while using the marshaller. I am new to JSONIX and I would like to convert JavaScript object to XML document. I generated mapping based on Schemat_JPK_FA(1)_v1-0.xsd file (in the project).
Could You @highsource please take a look and tell me why I get "Element [JPK] is not known in this context" error?
Here is my project
https://github.com/gitowiec/jsonix-tryout
And here is sample of XML I want to get from JSON:
<?xml version="1.0" encoding="UTF-8"?>
<JPK xmlns="http://jpk.mf.gov.pl/wzor/2016/03/09/03095/" xmlns:ns2="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/">
<Naglowek>
<KodFormularza kodSystemowy="JPK_FA (1)" wersjaSchemy="1-0">JPK_FA</KodFormularza>
<WariantFormularza>1</WariantFormularza>
<CelZlozenia>1</CelZlozenia>
<DataWytworzeniaJPK>2018-02-23T13:47:59.311+01:00</DataWytworzeniaJPK>
<DataOd>2018-01-01</DataOd>
<DataDo>2018-01-31</DataDo>
<DomyslnyKodWaluty>PLN</DomyslnyKodWaluty>
<KodUrzedu>2205</KodUrzedu>
</Naglowek>
<Podmiot1>
<IdentyfikatorPodmiotu>
<ns2:NIP>123123123</ns2:NIP>
<ns2:PelnaNazwa>qwerty</ns2:PelnaNazwa>
<ns2:REGON>123123</ns2:REGON>
</IdentyfikatorPodmiotu>
<AdresPodmiotu>
<ns2:KodKraju>PL</ns2:KodKraju>
<ns2:Wojewodztwo>pomorskie</ns2:Wojewodztwo>
<ns2:Powiat>dsadasd</ns2:Powiat>
<ns2:Gmina>dsadasd</ns2:Gmina>
<ns2:Ulica>gfdsgdsf</ns2:Ulica>
<ns2:NrDomu>11</ns2:NrDomu>
<ns2:Miejscowosc>fdsfdsf</ns2:Miejscowosc>
<ns2:KodPocztowy>44-444</ns2:KodPocztowy>
<ns2:Poczta>dsadasdsa</ns2:Poczta>
</AdresPodmiotu>
</Podmiot1>
<Faktura typ="G">
<P_1>2018-01-12</P_1>
<P_2A>FV SP / 198 / 01 / 2018</P_2A>
<P_3A>dsadasdsadasf</P_3A>
<P_3B>fdsfdsfdsfsdf</P_3B>
<P_3C>fdsfdsfdsfsdfsad</P_3C>
<P_3D>dsadsadsafgdsgsdfsdf</P_3D>
<P_4B>4324324324</P_4B>
<P_5B>4324324234</P_5B>
<P_6>2018-01-10</P_6>
<P_13_1>5316.00</P_13_1>
<P_14_1>1222.68</P_14_1>
<P_13_2>0.00</P_13_2>
<P_14_2>0.00</P_14_2>
<P_13_3>0.00</P_13_3>
<P_14_3>0.00</P_14_3>
<P_13_5>0.00</P_13_5>
<P_14_5>0.00</P_14_5>
<P_13_6>0.00</P_13_6>
<P_13_7>0.00</P_13_7>
<P_15>6538.68</P_15>
<P_16>false</P_16>
<P_17>false</P_17>
<P_18>false</P_18>
<P_19>false</P_19>
<P_20>false</P_20>
<P_21>false</P_21>
<P_23>false</P_23>
<P_106E_2>false</P_106E_2>
<P_106E_3>false</P_106E_3>
<RodzajFaktury>VAT</RodzajFaktury>
</Faktura>
<FakturaWiersz typ="G">
<P_2B>FV SP / 9 / 02 / 2018</P_2B>
<P_7>Transport - UPS</P_7>
<P_8A>sztuk</P_8A>
<P_8B>1</P_8B>
<P_9A>15.37</P_9A>
<P_11>15.37</P_11>
<P_12>23</P_12>
</FakturaWiersz>
<FakturaWierszCtrl>
<LiczbaWierszyFaktur>399</LiczbaWierszyFaktur>
<WartoscWierszyFaktur>20383.81</WartoscWierszyFaktur>
</FakturaWierszCtrl>
</JPK>
Activity
Fixing highsource/jsonix#192.
Fixing highsource/jsonix#192.
highsource commentedon May 10, 2018
I've sent you a PR with the fix:
gitowiec/jsonix-tryout#1
There were three problems with your code:
require('./mappings/JPK')as mapping, should berequire('./mappings/JPK').JPK. Generated modules export mappings as a property of the mapping's name.{JPK: value}to work, your target namespace has to be associated with the empty namespace.nipinstead ofNIP.With a few fixes I could generate the following XML:
Merge pull request #1 from highsource/master
gitowiec commentedon May 10, 2018
Thank You Very Much for Your Support,
Is it possible to pretty print XML string and make new lines after every > closing of opening tag?
I can't find API document where I could lookup parameters of
marshaller.marshalString()highsource commentedon May 10, 2018
You're welcome.
No, there are now built-in support for pretty-printing. Jsonix uses standard
XMLSerializerwhich, as far as I know, does not support pretty-printing. Quick SO search did not produce any good results.If you figure this out, please let me know.
gitowiec commentedon May 10, 2018
I used this package to pretty print XML https://www.npmjs.com/package/xml-formatter
And if I may ask, is there option to make
marshaller.marshalString()allow using key names (localName's) beginning with UpperCase and not stripping underscore? Just make it leave property names unchanged?I would like this behaviour because using
cxsdpackage I can generate TypeScript types for JSON data structure and that types have property names same as original element names (Naglowek instead of naglowek, Podmiot1 instead of podmiot1, P_2A instead of p2A, and so on)highsource commentedon May 11, 2018
No, not at the moment. File a feature request if you want this.
gitowiec commentedon May 11, 2018
Ok I think it's a jsonix-schema-compiler feature so I just reported feature-request there highsource/jsonix-schema-compiler#82
highsource commentedon May 11, 2018
Correct. Well done, thanks!