| Author |
Message |
daniel.todero
Newbie
Joined: 28 May 2014
Location: Brazil
Online Status: Offline
Posts: 2
|

Topic: Error in formula with optional tag Posted: 28 May 2014 at 4:55am |
|
Good Morning!
I created a Report using XSD but I'm having problems when I fill it with XML using dataset.
XSD Example Defination Table ICMS40
TABLE ICMS40 has the follow definations:
<orig>
<CST>
<vICMS>
I'v in crystal reports, one formule that uses the field vICMS.
The problem is that <vICMS> is a optional tag, so... some XML's that miss it fail when I try open the reports.
I really don't understand, why I thought XSD should be like a table and if XML's haven't <vICMS>, it should apear
NULL in field vICMS. Otherwise it fail, because vICMS dissapear in run-time in report, occoring the error "field does't exist".
The code to fill dataset:
Dim dsDados As New DataSet
dsDados.ReadXml('c:\File.XML')
...
v_reportdocument.SetDataSource(dsDados)
The formule in Crystal Reports:
if not isNull({ICMS40.vICMS}) then '' Not working.
{ICMS40.vICMS}
Tks a lot!
ATt,
Daniel Todero
Brazil
|
IP Logged |
|
|
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|

Posted: 29 May 2014 at 3:20am |
|
A lot of this has to do with how the dataset is built. If none of the records in the XML contains the vICMS field, then the field won't be defined in the dataset. At that point Crystal with throw an error if you try to access the field because it doesn't exist. So, this error is really due to how MS is building the dataset that the report is using.
I haven't tested this but instead of creating dsDados as a new "generic" DataSet, I would define a DataSet in your application that includes a table that includes ALL of the fields that are in your xml, including the optional fields. You would then define dsDados as a new instance of that dataset and fill the table with the XML.
-Dell
|
|
|
IP Logged |
|
daniel.todero
Newbie
Joined: 28 May 2014
Location: Brazil
Online Status: Offline
Posts: 2
|

Posted: 29 May 2014 at 3:41am |
|
Thanks for replying, you really understood my problem and I agree with u.
But, I don't know how to create a dsDados with the whole structure instead dataset from a XMLs.
I was thinking if there are a way to create a dataset from XSD. Do u know some way to create a dataset from XSD ?
Even I create a new structure with all fields, how to fill it with a XML and pass it to crystal reports.
I don't know if there are a way to do this, for this reason I'm asking help to understant that problem.
Thanks a lot.
|
IP Logged |
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|

Posted: 29 May 2014 at 5:31am |
|
Yes - when you create a dataset in an XSD, that becomes a sub-class of DataSet so you can use it just like one but you can also access the specific tables in the XSD.
So, assuming your existing XSD is called MyDataSet and it contains the table ICMS40, here is what you would do:
MyDataSet dsDados = new MyDataSet();
dsDados.ICMS40.ReadXml("c:\file.XML");
-Dell
MDataSet
|
|
|
IP Logged |
|
|
|