i have xml template (reporttemplate.xml) following:
<report xmlns:rd="http://schemas.microsoft.com/sqlserver/reporting/reportdesigner" xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition"> <reportsections> <reportsection> <body> <reportitems> <tablix name="tablix1"> <tablixbody> <tablixcolumns> </tablixcolumns> <tablixrows> </tablixrows> </tablixbody> </tablix> </reportitems> </body> </reportsection> </reportsections> </report>
i have created xml snippets (tablixrow.xml) not qualified xml documents such
<tablixrow> <height>0.26736in</height> </tablixrow>
in console app trying load both files , insert tablixrow code block tablixrows node of parent document
private static xdocument generatereport(list<string>fieldnames) { //load base template xdocument report = xdocument.load("templates/reporttemplate.xml"); xnamespace ns = report.root.name.namespace; //load row template xdocument trows = xdocument.load("templates/tablixrow.xml"); //and here stuck return report; }
i'm new linq , trying understand how navigate "tablixrows" node , insert trows block of code.
can provide points of reference or examples. have see far navigated , id. cannot use id's in schema , need rely on node
-cheers
private static xdocument generatereport(list<string>fieldnames) { xdocument report = xdocument.load("templates/reporttemplate.xml"); xnamespace ns = report.root.name.namespace; xelement row = xelement.load("templates/tablixrow.xml"); // change namespace loaded xml elements foreach (var element in row.descendantsandself()) element.name = ns + element.name.localname; var rows = xdoc.descendants(ns + "tablixrows").single(); rows.add(row); return report; }
if not change namespace row template xml, after adding report document have default namespace (which don't want):
<tablixrows> <tablixrow xmlns=""> <height>0.26736in</height> </tablixrow> </tablixrows>
if of templates have attributes, need provide namespace attributes also.
Comments
Post a Comment