I have written one xquery to get count of my records based on some conditions and would like to put the result as a column value in a Template document.
How can I call the xquery from the template in this case
Below is the Xquery which calls all documents from collection :GTM2_Shipment and gives count of records based on given condition.
xquery version "1.0-ml";
fn:count(
for $x in collection("GTM2_Shipment")
let $currentdt := fn:current-date()
let $sixmonthAgo := $currentdt - xs:yearMonthDuration("P6M")
where ($x/*:Shipment/*:Ancillary/*:QuotePrice/text() != 0) and
($x/*:Shipment/*:ASN/*:TrackedItem/*:Consignment/*:ConsignmentHeader/*:CargoSummary/*:TransMode/text() = 'Road')
and
(fn:substring($x/*:Shipment/*:ASN/*:TrackedItem/*:Consignment/*:Bookings/*:CargoBookingHeader/*:BookingCreateDt,0,11) gt
(format-date($sixmonthAgo, "[Y0001]-[M01]-[D01]")))
return $x
)
Example Template below where I want to add one more column named CountByRoad and add the above xquery and it refers the same collection -GTM2_Shipment:
xquery version "1.0-ml";
import module namespace tde = "http://marklogic.com/xdmp/tde" at "/MarkLogic/tde.xqy";
if (xdmp:database-name(xdmp:database()) = "data-hub-final-SCHEMAS") then
let $Custom_Shipment:=
<template xmlns="http://marklogic.com/xdmp/tde">
<path-namespaces>
<path-namespace>
<prefix>xmlns</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/Shipment</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns00</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/PurchaseOrderHeader</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns0</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/ConsignmentHeader</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns1</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/PurchaseOrderDrop</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns2</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/ItemDetail</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns5</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/TransportationUnitHeader</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns7</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/PurchaseOrderDelivery</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns9</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/BaseType</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns10</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/ASN</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns11</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/TransportationUnitHeader</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns13</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/ContainmentHeader</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns14</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/CargoBookingHeader</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ns15</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/Consignment</namespace-uri>
</path-namespace>
<path-namespace>
<prefix>ps</prefix>
<namespace-uri>http://www.globaltrademanagement_export.com/Shipment</namespace-uri>
</path-namespace>
</path-namespaces>
<context>//ps:Shipment</context>
<collections>
<collection>GTM2_Shipment</collection>
</collections>
<rows>
<row>
<schema-name>GTM2_Shipment</schema-name>
<view-name>Shipment_View</view-name>
<view-layout>sparse</view-layout>
<columns>
<column>
<name>Shipment_Ref</name>
<scalar-type>string</scalar-type>
<val>//ps:ShipmentRef</val>
<nullable>true</nullable>
</column>
<column>
<name>User</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns9:DocumentHeader/ns9:Version/ns9:CurrentVersion/ns9:User</val>
<nullable>true</nullable>
</column>
<column>
<name>PurchaseOrder</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns0:ConsignmentHeader/ns0:RefPurchaseOrders</val>
<nullable>true</nullable>
</column>
<column>
<name>Carrier_LocalCode</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns0:ConsignmentHeader/ns0:Carrier/ns9:LocalCode</val>
<nullable>true</nullable>
</column>
<column>
<name>Notify_PartyCode</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns0:ConsignmentHeader/ns0:Notify/ns9:Code</val>
<nullable>true</nullable>
</column>
<column>
<name>houseBill_Ref</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns0:ConsignmentHeader/ns0:HouseBillRef</val>
<nullable>true</nullable>
</column>
<column>
<name>primaryVessel</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns0:ConsignmentHeader/ns0:PrimaryVessel</val>
<nullable>true</nullable>
</column>
<column>
<name>Dept</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns0:ConsignmentHeader/ns0:Dept</val>
<nullable>true</nullable>
</column>
<column>
<name>Route</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns0:ConsignmentHeader/ns0:Route</val>
<nullable>true</nullable>
</column>
<column>
<name>transMode</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns0:ConsignmentHeader/ns0:CargoSummary/ns0:TransMode</val>
<nullable>true</nullable>
</column>
<column>
<name>OSP_PartyName</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns0:ConsignmentHeader/ns0:CargoSummary/ns0:OSP/ns9:PartyName</val>
<nullable>true</nullable>
</column>
<column>
<name>OSP_Code</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns0:ConsignmentHeader/ns0:CargoSummary/ns0:OSP/ns9:Code</val>
<nullable>true</nullable>
</column>
<column>
<name>Trans_UnitRef</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:Schedule/ns11:TransportationUnitHeader/ns11:PrimarytUnit/ns11:TransportUnit/ns11:TransUnitRef</val>
<nullable>true</nullable>
</column>
<column>
<name>POL_Name</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:Schedule/ns11:TransportationUnitHeader/ns11:PrimarytUnit/ns11:TransportUnit/ns11:PortOfLoading/ns9:PortName</val>
<nullable>true</nullable>
</column>
<column>
<name>POL_ETA_Sch_Dep</name>
<scalar-type>dateTime</scalar-type>
<val>//ns10:ASN/ns10:Schedule/ns11:TransportationUnitHeader/ns11:PrimarytUnit/ns11:TransportUnit/ns11:PortOfLoading/ns9:ScheduledDepartureDate</val>
<nullable>true</nullable>
<invalid-values>ignore</invalid-values>
</column>
<column>
<name>POL_ETA_Act_Dep</name>
<scalar-type>dateTime</scalar-type>
<val>//ns10:ASN/ns10:Schedule/ns11:TransportationUnitHeader/ns11:PrimarytUnit/ns11:TransportUnit/ns11:PortOfLoading/ns9:ActualDepartureDate</val>
<nullable>true</nullable>
<invalid-values>ignore</invalid-values>
</column>
<column>
<name>POL_ETA_Sch_Arr</name>
<scalar-type>dateTime</scalar-type>
<val>//ns10:ASN/ns10:Schedule/ns11:TransportationUnitHeader/ns11:PrimarytUnit/ns11:TransportUnit/ns11:PortOfLoading/ns9:ScheduledArrivalDate</val>
<nullable>true</nullable>
<invalid-values>ignore</invalid-values>
</column>
<column>
<name>POL_ETA_Act_Arr</name>
<scalar-type>dateTime</scalar-type>
<val>//ns10:ASN/ns10:Schedule/ns11:TransportationUnitHeader/ns11:PrimarytUnit/ns11:TransportUnit/ns11:PortOfLoading/ns9:ActualArrivalDate</val>
<nullable>true</nullable>
<invalid-values>ignore</invalid-values>
</column>
<column>
<name>POD_Name</name>
<scalar-type>string</scalar-type>
<val>//ns10:ASN/ns10:Schedule/ns11:TransportationUnitHeader/ns11:PrimarytUnit/ns11:TransportUnit/ns11:PortOfDischarge/ns9:PortName</val>
<nullable>true</nullable>
<invalid-values>ignore</invalid-values>
</column>
<column>
<name>BookingCreateDt</name>
<scalar-type>dateTime</scalar-type>
<val>//ns10:ASN/ns10:TrackedItem/ns15:Consignment/ns15:Bookings/ns14:CargoBookingHeader/ns14:BookingCreateDt</val>
<nullable>true</nullable>
<invalid-values>reject</invalid-values>
</column>
<column>
<name>Ancillary_QuotePrice</name>
<scalar-type>decimal</scalar-type>
<val>//ps:Ancillary/ps:QuotePrice</val>
<nullable>true</nullable>
<invalid-values>reject</invalid-values>
</column>
</columns>
</row>
</rows>
</template>
return
(
tde:template-insert("/GTM2/SHIPMENT_ShipmentView.xml",$Custom_Shipment),
"template inserted")
else ("Please select correct database.")
I don't think you can do what you want.
https://docs.marklogic.com/guide/app-dev/TDE#id_71415
For performance and security reasons, your path expressions are limited to a subset of XPath. For more details, see Template Driven Extraction (TDE) in the XQuery and XSLT Reference Guide.
https://docs.marklogic.com/guide/app-dev/TDE#id_99178
Templates support a dialect using a subset of XQuery with limited functionalities where only a subset of functions are available.
More complex operations like looping, FLWOR statements, iterations, and XML construction are not supported within the dialect. The property axis property:: is also not supported.
Related
I try to use FastReport open source to build reports from data I'll provide to the report.
I've found what I want in the demos (https://github.com/FastReports/FastReport/tree/master/Demos/OpenSource/DataFromBusinessObject/DataFromBusinessObject)
In this demo, I see in the report file that a BusinessObjectDataSourceis used, which seems to be what I want to use.
However, I don't see a way to add this kind of source in the community designer. Do I need to add all of this manually ? Or is there a way to generate the needed markup ? I can't find the solution on their site.
I found a way by making the needed xml by hand like this:
<BusinessObjectDataSource Name="Invoices" ReferenceName="Invoices" Enabled="true">
<Column Name="Reference" DataType="System.String"/>
<Column Name="Date" DataType="System.String"/>
<Column Name="CompanyName" DataType="System.String"/>
<Column Name="InvoiceEmail" DataType="System.String"/>
<Column Name="VAT" DataType="System.String"/>
<Column Name="Street" DataType="System.String"/>
<Column Name="Number" DataType="System.String"/>
<Column Name="City" DataType="System.String"/>
<Column Name="ZipCode" DataType="System.String"/>
<Column Name="Country" DataType="System.String"/>
<Column Name="TotalPrice" DataType="System.Decimal"/>
<Column Name="VATValue" DataType="System.Decimal"/>
<Column Name="VATPercentage" DataType="System.Decimal"/>
<Column Name="VATComment" DataType="System.String"/>
</BusinessObjectDataSource>
The only drawback is that I need to update this if my object changes (but at least is is working !)
I found a way to generate an empty report with the fields generated from a business object.
You only have to create an empty report object, call "RegisterBusinessObject()" on its Dictionary property, and then save the report itself:
var report = new Report();
report.Dictionary.RegisterBusinessObject(
new List<Invoice>(), // a (empty) list of objects
"Invoices", // name of dataset
2, // depth of navigation into properties
true // enable data source
);
report.save(#"invoiceReport.frx");
You still need to update the report description if your object changes, but at least you don't have to code it by hand!
it's been a while since I have used AWK, but now i have an XML file where I like to increase an Id for a specific column; so it's an excellent task for AWK.
In theory, to increase the Id, the line gets parsed, you fish out the Id into a variable, ++ it, and reconstruct the line to print to the resulting stream.
However, when I use the variable ( x = sprintf(...)) I got weird results, so I used printf to debug the thing. And now the weird part : printf dumps exactly the right Id, but the variable gets rubbish, although they have the same input & syntax ...
Must be somethinig really silly off course, but I can't put my finger on it.
All Ids are in the form :
<column name="Id" type="System.Int32">x</column>
This is the code :
#!/bin/ksh
cd /mnt/c/J/D/Work/GIT/Repos/SkillsNG/SkillsNG.WebTests/Snapshots
print -n "Snapshot name: "
read snapshot
defaultId=0
print -n "Start increasing from Id [$defaultId]":
read id
[[ "$id" = '' ]] && id=$defaultId
cat $snapshot | awk -F '>' 'BEGIN {process=0;} {
if (match($0, /SecurityPermissions/))
{process=1;}
else
{
if (!process)
{
# just dump all tables up to SecurityPermissions, no processing needed
print;
next;
}
}
if (match($1, /<column name="Id" type="System.Int32"/))
{
if(match($2,/[0-9]*/))
{
printf "param 1: %s\n", $1
printf "param 2: %s\n", $2
printf "Id value : %s\n", substr($2, 1, index($2,"\<")-1);
val = sprintf("%s", substr($2,1, index($2,"\<")-1));
printf "value in variable: %s\n", $val;
newval = strtonum(val);
printf "new: %s\n", $newval
}
}
else print $0;
}' > $snapshot.new
# mv $snapshot $snapshot.old
# mv $snapshot.new $snapshot
cd -
And this a simple test xml:
<snapshot culture="en-US">
<table name="[dbo].[SecurityPermissions]">
<row>
<column name="Id" type="System.Int32">1</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">1</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
<column name="Id" type="System.Int32">2</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">50</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
<column name="Id" type="System.Int32">3</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">51</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
<column name="Id" type="System.Int32">4</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">52</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
<column name="Id" type="System.Int32">5</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">53</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
<column name="Id" type="System.Int32">6</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">54</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
<column name="Id" type="System.Int32">7</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">56</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
<column name="Id" type="System.Int32">8</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">57</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
<column name="Id" type="System.Int32">9</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">77</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
<column name="Id" type="System.Int32">10</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">78</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
<column name="Id" type="System.Int32">11</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">80</column>
<column name="Access" type="System.Int32">15</column>
</row>
</table>
</snapshot>
Result file :
<snapshot culture="en-US">
<table name="[dbo].[SecurityPermissions]">
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 1</column
Id value : 1
value in variable: <column name="Id" type="System.Int32"
new: <column name="Id" type="System.Int32"
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">1</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 2</column
Id value : 2
value in variable: 2</column
new: 2</column
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">50</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 3</column
Id value : 3
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">51</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 4</column
Id value : 4
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">52</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 5</column
Id value : 5
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">53</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 6</column
Id value : 6
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">54</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 7</column
Id value : 7
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">56</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 8</column
Id value : 8
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">57</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 9</column
Id value : 9
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">77</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 10</column
Id value : 10
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">78</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 11</column
Id value : 11
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">80</column>
<column name="Access" type="System.Int32">15</column>
</row>
</table>
</snapshot>
As can be seen from the result file, the Id value (via printf) works correctly, but the same construct to a variable (via sprintf) produces garbage.
Anybody got an idea what is going on?
Thanks in advance.
Cheers,
DJ
First of all, you should not try to do these things with awk or sed or anything like that. XML is a complicated data-structure with all its ugliness connected to it. While a simple awk might do it now, it will fail all of a sudden and you will not know what hit you.
If you want to increment that particular value, you could use the following xmlstarlet command:
$ xmlstarlet ed --update '//table/row/column[#name="Id"]' -x ".+1" test.xml
It reads like this: xmlstarlet will (ed) edit the file test.xml by (--update) updating all nodes that match the XPath expression ('//table/row/column[#name="Id"]' :: all nodes column child of row child of of table with an attribute name equal to Id) and change its value with an XPath expression -x ".+1" (increment current value (.))
To answer your question: you obtain the unexpected results with awk because you reference some variables using $. Example:
val = sprintf("%s", substr($2,1, index($2,"\<")-1));
printf "value in variable: %s\n", $val;
In your first line, you compute the value of val but in the second line, you use $val. The latter actually returns the value of the field with number val. So if val=2, then $val will return $2, i.e. the content of the second field.
For some reason when I generate a change log with Liquibase it uses wrong precision. It generates a column with data type NUMBER(0,-127).
Does anybody know how to fix this?
<changeSet author="sfasdf (generated)" id="1357744702717-1">
<createTable schemaName="BLA" tableName="ADT_PAGE_ACCESS">
<column name="ID" type="NUMBER(0,-127)">
<constraints nullable="false" primaryKey="true" primaryKeyName="ADT_PAGE_ACCESS_PK" primaryKeyTablespace="ZON_IND1"/>
</column>
<column name="PAGE_ID" type="VARCHAR2(100 BYTE)">
<constraints nullable="false"/>
</column>
<column defaultValueComputed="sysdate" name="ACCESSED" type="DATE">
<constraints nullable="false"/>
</column>
<column name="CUSTOMER_ID" type="NUMBER(0,-127)"/>
<column name="USERID" type="VARCHAR2(25 BYTE)"/>
</createTable>
</changeSet>
I have an ASP.net application in c# where I have a dataset which I can transfer to xml by using the following simple codeblock:
string result;
using (StringWriter sw = new StringWriter())
{
ds.WriteXml(sw);
result = sw.ToString();
}
Which generates an xml block like the following:
<NewDataSet>
<ImageInfo>
<ImageID>1</ImageID>
<ImageName>untitled.bmp</ImageName>
<ImagePath>Some Path</ImagePath>
<Width>800</Width>
<Height>190</Height>
<TileSize>256</TileSize>
<Overlap>1</Overlap>
<MimeType>image/jpeg</MimeType>
<Scale />
</ImageInfo>
</NewDataSet>
This is obviously an example of one row, there are multiple rows in the dataset. Now, I dont know how to format a XML block dynamically.
Can anyone point me to some good tutorials on this?
I want the XML to be formatted like the following
<data>
<Columns>
<Column Name= "ImageID"/>
<Column Name= "ImageName"/>
<Column Name= "ImagePath"/>
<Column Name= "Width"/>
<Column Name= "Height"/>
<Column Name= "TileSize"/>
<Column Name= "Overlap"/>
<Column Name= "MimeType"/>
<Column Name= "Scale"/>
</Columns>
<Rows>
<Row>
<Cell>1</Cell>
<Cell>untitled.bmp</Cell>
<Cell>Some Path</Cell>
<Cell>800</Cell>
<Cell>190</Cell>
<Cell>256</Cell>
<Cell>1</Cell>
<Cell>image/jpeg</Cell>
<Cell></Cell>
</Row>
<Row>
.
.
.
</Row>
</Rows>
</data>
Can anyone guide me how to do this?
In my application, I wont be knowing the structure of the dataset beforehand. i.e. there can be a resulting dataset where I have more columns than the ones described in the example. How should I go about this? Any help would be much appreciated.
Try using a DataTable and then convert that DataTable to an XML stream or a file.
DataTable myDataTable = myDataSet.Tables[0];
myDataTable.WriteXml(..);
You will find whole bunch of overloads like TextWriter, Stream. Finally you need to modify that xml to add the nodes besides that DataTable.
This can be a work around. The code standard can be better but for now you can use the following:
XmlDocument doc = new XmlDocument();
XmlDocument Outputdoc = new XmlDocument();
doc.LoadXml("<NewDataSet> <ImageInfo> <ImageID>1</ImageID> <ImageName>untitled.bmp</ImageName> <ImagePath>Some Path</ImagePath> <Width>800</Width> <Height>190</Height> <TileSize>256</TileSize> <Overlap>1</Overlap> <MimeType>image/jpeg</MimeType> <Scale /> <ImageID>1</ImageID> <ImageName>untitled.bmp</ImageName> <ImagePath>Some Path</ImagePath> <Width>800</Width> <Height>190</Height> <TileSize>256</TileSize> <Overlap>1</Overlap> <MimeType>image/jpeg</MimeType> <Scale /></ImageInfo> </NewDataSet> ");
XmlNode node = doc.SelectSingleNode("/NewDataSet/ImageInfo");
XmlNodeList nodes = node.ChildNodes;
XmlDocument newdoc = null;
StringBuilder sb = new StringBuilder("<data><Columns>");
string lastNode=string.Empty;
string firstNode = string.Empty;
foreach (XmlNode n in node.ChildNodes)
{
if(n.Name.Equals(firstNode))
break;
if (string.IsNullOrEmpty(firstNode))
firstNode = n.Name;
newdoc = new XmlDocument();
XmlNode newNode = newdoc.CreateElement("Column");
XmlAttribute newAttribute = newdoc.CreateAttribute("Name");
newAttribute.Value = n.Name;
newNode.Attributes.Append(newAttribute);
newdoc.AppendChild(newNode);
sb.Append(newdoc.InnerXml);
lastNode=n.Name;
}
sb.Append("</Columns><Rows><Row>");
foreach (XmlNode xnode in node.ChildNodes)
{
XmlDocument newdoc1 = new XmlDocument();
XmlNode newNode = newdoc1.CreateElement("Cell");
newNode.InnerText = xnode.InnerText;
newdoc1.AppendChild(newNode);
sb.Append(newdoc1.InnerXml);
if (xnode.Name.Equals(lastNode))
sb.Append("</Row>");
}
sb.Append("</Rows></data>");
This is a very quick way to accomplish your task. You are free to standarize the code. Now look at the output which looks same as you need:
<data>
<Columns>
<Column Name="ImageID" />
<Column Name="ImageName" />
<Column Name="ImagePath" />
<Column Name="Width" />
<Column Name="Height" />
<Column Name="TileSize" />
<Column Name="Overlap" />
<Column Name="MimeType" />
<Column Name="Scale" />
</Columns>
<Rows>
<Row>
<Cell>1</Cell>
<Cell>untitled.bmp</Cell>
<Cell>SomePath</Cell>
<Cell>800</Cell>
<Cell>190</Cell>
<Cell>256</Cell>
<Cell>1</Cell>
<Cell>image/jpeg</Cell>
<Cell></Cell>
</Row>
<Cell>1</Cell>
<Cell>untitled.bmp</Cell>
<Cell>Some Path</Cell>
<Cell>800</Cell>
<Cell>190</Cell>
<Cell>256</Cell>
<Cell>1</Cell>
<Cell>image/jpeg</Cell>
<Cell></Cell>
</Row>
</Rows>
</data>
Note: I have used the same data collection to make two rows of data.
I'm having a strange issue with my AdvancedDataGrid. I have a pretty basic (no frills) XML file that I'm pulling the data from and trying to create a hierarchical view in my ADG. It mostly works, but when my top level node only has one child I see the folder icon but no twistee to see the second level of data. If there's no second level or 2 or more it looks and works just fine. Has anyone run into this before or maybe I have it set up wrong? Here's some of the code:
XML:
<root>
<item item_id="4" title="First Document Title 33.1" author="Mark Pusateri" pubDate="4/10/2011">
<tag name="Advisory" type="Service line"/>
<tag name="GSS" type="Function/source"/>
<tag name="Global" type="Area"/>
</item>
<item item_id="5" title="First Document Title 4" author="Mark Pusateri" pubDate="5/11/2011">
<tag name="Americas" type="Area"/>
</item>
<item item_id="6" title="First Document Title 5" author="Mark Pusateri" pubDate="6/12/2012">
<tag name="Japan" type="Area"/>
</item>
<item item_id="7" title="First Document Title 6" author="Mark Pusateri" pubDate="3/13/2009"/>
<item item_id="8" title="First Document Title 6.1" author="Mark Pusateri" pubDate="3/14/2011"/>
<item item_id="9" title="First Document Title 7" author="Mark Pusateri" pubDate="4/9/2011">
<tag name="Americas" type="Area"/>
</item>
MXML:
<mx:AdvancedDataGrid id="mainADG" width="100%" height="100%">
<mx:dataProvider>
<mx:HierarchicalData source="{mainArrayColl}"
childrenField="tag" />
</mx:dataProvider>
<mx:groupedColumns>
<mx:AdvancedDataGridColumn headerText="Title" dataField="title"/>
<mx:AdvancedDataGridColumn headerText="Author" dataField="author"/>
<mx:AdvancedDataGridColumn headerText="Publication date" dataField="pubDate"/>
<mx:AdvancedDataGridColumnGroup headerText="Tags" >
<mx:AdvancedDataGridColumn headerText="Name" dataField="name"/>
<mx:AdvancedDataGridColumn headerText="Type" dataField="type"/>
</mx:AdvancedDataGridColumnGroup>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
Use # symbol with Data-Field because all of these are attribute
<mx:AdvancedDataGrid id="mainADG" width="100%" height="100%">
<mx:dataProvider>
<mx:HierarchicalData source="{mainArrayColl}" />
</mx:dataProvider>
<mx:groupedColumns>
<mx:AdvancedDataGridColumn headerText="Title" dataField="#title"/>
<mx:AdvancedDataGridColumn headerText="Author" dataField="#author"/>
<mx:AdvancedDataGridColumn headerText="Publication date" dataField="#pubDate"/>
<mx:AdvancedDataGridColumnGroup headerText="Tags" >
<mx:AdvancedDataGridColumn headerText="Name" dataField="#name"/>
<mx:AdvancedDataGridColumn headerText="Type" dataField="#type"/>
</mx:AdvancedDataGridColumnGroup>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
I removed childrenField="tag" b/c its works for me
hopes that helps