libxml xmlXPathEvalExpression order - c

I've started using libxml in C, and I'm using the xmlXPathEvalExpression function to evaluate XPath.
My XML file actually represents a table, with each child node representing a row in that table and its attributes are the corresponding values, so the order is important.
I couldn't find information about that function in regards to its order. Does it return the nodes in the document order
for example, the following xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<TABLE0>
<Row Item0="1" Item1="2"/>
<Row Item0="2" Item1="3"/>
<Row Item0="3" Item1="4"/>
</TABLE0>
<TABLE1>
<Row Item0="1" Item1="12"/>
<Row Item0="6" Item1="15"/>
</TABLE1>
</Root>
Can I be sure that after evaluating /Root/TABLE0/* and getting the nodeset, calling nodeSet->nodeTab[0] would get the first row, nodeSet->nodeTab[1] would get the second and so on?
If not, is there a way to sort it by document order?
Thanks

Yes, the results of XPath expressions evaluated with xmlXPathEvalExpression or compiled with xmlXPathCompile are always sorted in document order. (Internally, they're compiled by calling xmlXPathCompileExpr with a true sort flag.)

Related

Jaspersoft studio connecting list with sub dataset with report main data set

I'm new at jaspersoft studio and I couldn't find proper solution for my problem. My impression is that this is pretty simple but I can't solve it on my own. I think I need step by step explanation on how to do it...
So, this what I what to achieve:
I have XML file with structure like this:
`
<Model>
<chapter>
<id>943</id>
<name>ChapterName</name>
<status>0/2</status>
<items>
<id>56441</id>
<number>1.</number>
<check>Default</check>
<question>text</question>
</items>
<items>
<id>56542</id>
<number>2.</number>
<check>Default</check>
<question>text</question>
</items>
</chapter>
<chapter>
<id>944</id>
<name>ChapterName</name>
<status>0/2</status>
<items>
<id>45542</id>
<number>1.</number>
<check>Default</check>
<question>text</question>
</items>
<items>
<id>21456</id>
<number>2.</number>
<check>Default</check>
<question>text</question>
</items>
</chapter>
</Model>
`
2. My report should look like this:
Name of chapter and below all items that are belonging to that chapter
it should list all chapters with its belonging items
Best solution is to sort items based on the id of chapter because it is unique integer
I created main dataset with fields of /Model/chapter
and sub dataset with fields of /Model/chapter/items
In report in detail band I put id and name (of chapter) and below it I created List with Dataset Run to be sub dataset I created (/Model/chapter/items)
what i see now in previewer is list of chapters and all items from file are joined to each chapter
It needs to be filtered to join items to chapter based on the chapter id
I need to create parameter which will sort items but i dont know how to create it to work.
It seems pretty easy but I just dont know how to make it work. Can someone please help me?

Having an issue with XML containing nested objects to POCO (de)serialisation (VB.Net)

I've created an SP in SQL Server that returns as XML. I decided to do this as the information has contacts and addresses in it and I wanted to reduce the amount of data I get.
<Accounts>
<Account>
<Company />
<ContactNumber />
<Addresses>
<Address>
<Line1 />
....
</Address>
<Addresses>
<Contacts>
<Contact>
<Name />
....
</Contact>
<Account>
</Accounts>
I have found SqlCommand.ExecuteXmlReader but I'm confused as to how to serialise this into my POCO. Can someone point me at what my next step is. (The POCO was created by the Insert XML as a class menu item in VS2019).
My Google fu is letting me down as I'm not sure what I should be looking for to help understand how to serialize the XML into something that will allow me to go with Foreach Account in AccountsClass type logic.
Any help is greatly appreciated.
PS The XML above is just a sample to show what I'm doing. The actual data is over 70 fields and with two FK joins the initial 40000 rows is well in excess of 1.8 million once selected as a normal dataset.
EDIT: Just in case someone stumbles on this and are in the same situation I was in.
When preparing a sample record for the Past XML to class make sure you have more than one record if you are expecting something similar to my example above. (The class changes to support more than one record.)
You get very different results when searching for deserialize when doing your research. This small change resulted in me figuring out the issue.

What does the error "The dataset refers to a shared dataset which is not available." mean?

I have a report template (.rdl file) that has an embedded dataset 'X' that refers to a shared dataset 'Y' (.rsd file). Both files are located in the same folder.
When I try to generate a report, I get the error "The dataset 'X' refers to a shared dataset 'Y' which is not available."
The datasets do not contain comma-separated strings or empty values.
UPDATE (2019-06-07): contrary to the above, the data did contain empty values. I didn't realize a filter was emptying the final result.
I've made sure that the data source is shared, as well.
Other shared datasets are recognized, but this one isn't.
I've looked at database permissions, but I've been able to run the SQL queries from the datasets in SSMS without problems, which seems to indicate that the permissions are valid. Perhaps the application using the datasets needs specific database permissions..?
This is the problematic dataset:
<?xml version="1.0" encoding="utf-8"?>
<SharedDataSet xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/shareddatasetdefinition">
<DataSet Name="">
<Query>
<DataSourceReference>XXX</DataSourceReference>
<DataSetParameters>
<DataSetParameter Name="#Foo">
<ReadOnly>false</ReadOnly>
<Nullable>false</Nullable>
<OmitFromQuery>false</OmitFromQuery>
<rd:DbType>Object</rd:DbType>
</DataSetParameter>
</DataSetParameters>
<CommandText>***a SQL query***</Query>
<Fields>***some fields***
</Fields>
<Filters>***some filters***
</Filters>
</DataSet>
</SharedDataSet>
This one seems to pose no problems:
<?xml version="1.0" encoding="utf-8"?>
<SharedDataSet xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/shareddatasetdefinition">
<DataSet Name="">
<Query>
<DataSourceReference>XXX</DataSourceReference>
<DataSetParameters>
<DataSetParameter Name="#FooId">
<ReadOnly>false</ReadOnly>
<Nullable>false</Nullable>
<OmitFromQuery>false</OmitFromQuery>
<rd:DbType>Object</rd:DbType>
</DataSetParameter>
<DataSetParameter Name="#BarId">
<ReadOnly>false</ReadOnly>
<Nullable>false</Nullable>
<OmitFromQuery>false</OmitFromQuery>
<rd:DbType>Object</rd:DbType>
</DataSetParameter>
</DataSetParameters>
<CommandText>***SQL QUERY***</CommandText>
</Query>
<Fields>***some fields***
</Fields>
<Filters>
<Filter>***some filters***
</Filter>
</Filters>
</DataSet>
</SharedDataSet>
UPDATE (2019-06-06): Apparently, removing the filters and ensuring that the query does not yield an empty result fixes the error. If there are filter(s) or if the query yields an empty result, the error returns. I have no clue yet why this is so.
UPDATE (2019-06-07): The filter caused the dataset to return an empty set of records (0 rows). This is what seems to cause the error. In all tests I did, cases where there's at least one row of data worked and cases where there's 0 rows showed the error.

XML Attributes to SQL

I've seen posts that are similar to what I'm about to ask, but I can't find anything that actually solves my problem. I've seen (and duplicated) getting XML tags into SQL, but not getting the attributes of the tags into SQL.
Background: We use a program that runs "events" based on each event's schedule. The schedules are in XML. Ultimately, I'm trying to compare the last time a given event ran to the last time it should have run, based on its schedule. Once I get the schedules out of XML and into a table (or tables), I'm confident I can take it from there. But, I'm STRUGGLING with that first step.
Below is the XML I'm trying to get into a table (or tables). Any help would be greatly appreciated!!
<Schedule LastModified="2016-06-27T21:02:10.6041531Z" TimeZone="(UTC-06:00) Central Time (US & Canada)" ConvertedToUTC="True" Type="Weekly">
<Beginning StartDate="2016-05-26T22:26:00.0000000" />
<Block BlockType="AllDay" Interval="10" IntervalType="Minute" SetType="Inclusive" Start="15:00:00" End="17:00:00" Duration="02:00:00" />
<Interval Type="Weekly" RecurEveryX="1" Sunday="False" Monday="True" Tuesday="True" Wednesday="True" Thursday="True" Friday="True" Saturday="False" />
<Ending Type="NoEndDate" />
</Schedule>
Don't know, where you have your issues... Reading this XML is rather trivial (did not code all of the values, but you'll get the idea):
DECLARE #mockup TABLE(YourXML XML);
INSERT INTO #mockup VALUES
(N'<Schedule LastModified="2016-06-27T21:02:10.6041531Z" TimeZone="(UTC-06:00) Central Time (US & Canada)" ConvertedToUTC="True" Type="Weekly">
<Beginning StartDate="2016-05-26T22:26:00.0000000" />
<Block BlockType="AllDay" Interval="10" IntervalType="Minute" SetType="Inclusive" Start="15:00:00" End="17:00:00" Duration="02:00:00" />
<Interval Type="Weekly" RecurEveryX="1" Sunday="False" Monday="True" Tuesday="True" Wednesday="True" Thursday="True" Friday="True" Saturday="False" />
<Ending Type="NoEndDate" />
</Schedule>');
SELECT m.YourXML.value(N'(/Schedule/#LastModified)[1]',N'datetime') AS Schedule_LastModified
,m.YourXML.value(N'(/Schedule/#TimeZone)[1]',N'nvarchar(max)') AS Schedule_TimeZone
,m.YourXML.value(N'(/Schedule/Beginning/#StartDate)[1]',N'datetime') AS Beginning_StartDate
,m.YourXML.value(N'(/Schedule/Block/#BlockType)[1]',N'nvarchar(max)') AS Block_BlockType
,m.YourXML.value(N'(/Schedule/Block/#Interval)[1]',N'int') AS Block_Interval
,m.YourXML.value(N'(/Schedule/Interval/#Type)[1]',N'nvarchar(max)') AS Interval_Type
FROM #mockup AS m;
If this is not your solution, please edit your question: Add your own attempt, the wrong output and the expected output. Your explanation did not make is all clear to me...

How to retrieve multiple XML siblings - SQL Server

I have searched thoroughly and not found any examples or guidance on how I can query and retrieve the values of multiple XML siblings.
There are plenty of examples on how to retrieve a single sibling value.
For example given the following XML fragment:
<StoreSurvey>
<AnnualSales>800000</AnnualSales>
<AnnualRevenue>80000</AnnualRevenue>
<BankName>United Security</BankName>
<BusinessType>BM</BusinessType>
<YearOpened>1996</YearOpened>
<Specialty>Mountain</Specialty>
<SquareFeet>21000</SquareFeet>
<Brands>2</Brands>
<Internet>ISDN</Internet>
<NumberEmployees>13</NumberEmployees>
<Products Type="Bikes">
<Product>Mountain</Product>
<Product>Road</Product>
<Product>Racing</Product>
</Products>
<Products Type="Clothes">
<Product>Jerseys</Product>
<Product>Jackets</Product>
<Product>Shorts</Product>
</Products>
</StoreSurvey>
If I want to retrieve the value of <AnnualSales>, I can execute the following statement in query analyzer:
SELECT Survey_untyped.query('/StoreSurvey/AnnualSales')
FROM Stores;
The result set will properly display
<AnnualSales>800000</AnnualSales>
However, what if I want to retrieve both <AnnualSales> AND <AnnualRevenue>? How would I do that?
The query should provide a result set looking like:
<AnnualSales>800000</AnnualSales>
<AnnualRevenue>80000</AnnualRevenue>
Or what if I want three of the sibling values “BankName” in addition to those values? Result set would look like this:
<AnnualSales>800000</AnnualSales>
<AnnualRevenue>80000</AnnualRevenue>
<BankName>United Security</BankName>
Does anyone know the answer to that?
This XPath, which uses the self:: axis,
/StoreSurvey/*[self::AnnualSales or self::AnnualRevenue or self::BankName]
will select
<AnnualSales>800000</AnnualSales>
<AnnualRevenue>80000</AnnualRevenue>
<BankName>United Security</BankName>
from your XML, as requested.

Resources