Receiving an error 'System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.'
I know that the error message in the title indicates that the application that I’m running the XML code in doesn’t seem to recognize it as XML. I’ve compared it to other coding I’ve used recently and cannot find the issue. One big difference, however, is that I’m using XSLT along with it, which may be the cause. I’ve included a snip of the XML & XSLT coding for reference.
<?xml version="1.0" encoding="UTF-8"?> <GLPayrollExportConfiguration> <definitions> <FileType Value="CSV"/> <FileName> <Value Value="GL_Summary_"/> <Value Value="paygroup_xref"/> <Value Value="_"/> <Value Value="payrun_payperiod_and_suffix"/> <Value Value="_"/> <Value Value="transaction_timestamp"/> <Value Value=".csv"/> </FileName> <Settings> <SplitMode Value="HOME_LOCATION_SPLIT"/> <ChartOfAccountXRefCode Value="GL"/> <RunOnPayRunCommit Value="True"/> </Settings> <Header> <Text Value="Posting Date,"/> <Text Value="Document Type,"/> <Text Value="Account Type,"/> <Text Value="Account No,"/> <Text Value="Fund No,"/> <Text Value="Dimension Speedkey Code,"/> <Text Value="Dimension 1,"/> <Text Value="Dimension 2,"/> <Text Value="Dimension 3,"/> <Text Value="Dimension 4,"/> <Text Value="Dimension 5,"/> <Text Value="Dimension 6,"/> <Text Value="Dimension 7,"/> <Text Value="Dimension 8,"/> <Text Value="External Document No,"/> <Text Value="Description,"/> <Text Value="Amount,"/> </Header> <Columns> <Column Name="PostingDate" DataType="datetime" Source="data" Value="payrun_pay_date" Sort="true"/> <Column Name="ColumnC" DataType="string" Source="mapping"/> <Column Name="AccountNo" DataType="string" Source="data" Value="payrun_category_override_journal_number"/> <Column Name="FundNo" DataType="string" Value="UNREST"/> <Column Name="DimensionSpeedkeyCode" DataType="string" Source="mapping"/> <Column Name="Description" DataType="string" Source="mapping"/> <Column Name="Amount" DataType="number" Source="data" Value="payrun_amount" Function="sum" /> </Columns> </definitions> <MappingDefinitions> <definition> <criteriaset> <!-- EXCLUDE MEMO DEDUCTIONS AND TAXABLE BENEFITS / JOURNAL NUMBER CODED AS exclude, Exclude, or EXCLUDE --> <criteria item="payrun_category_override_journal_number" op="ne">EXCLUDE</criteria> <criteria item="payrun_category_override_journal_number" op="ne">Exclude</criteria> <criteria item="payrun_category_override_journal_number" op="ne">exclude</criteria> <!-- EXCLUDE RECORDS WITH with 0 VALUE --> <criteria item="payrun_amount" op="ne" opDataType="number">0</criteria> </criteriaset> <mapping> <mapto columnname="Col C"> <Value Value="	"/><Value Value="PAYROLL"/> <Value Value="payrun_pay_date"/> </mapto> <mapto columnname="Dimension Speedkey Code"> <Value Value="	"/><Value Value="override_segment_charged_dynamic_org_level_onsitedepartment"/> <Value Value="override_segment_dynamic_labor_metric_code_CostNumber"/> </mapto> <mapto columnname="Description"> <Value Value="	"/><Value Value="payrun_pay_date"/> <Value Value=" "/><Value Value="payrun_category_name"/> </mapto> </mapping> </definition> </MappingDefinitions> <ColumnFormats> <ColumnFormat Name="PostingDate" Format="MM.dd.yy"/> <ColumnFormat Name="ColC" Format="YYYYMMDD"/> <ColumnFormat Name="AccountNo" WrapChar="""/> <ColumnFormat Name="DimensionSpeedkeyCode" WrapChar="""/> <ColumnFormat Name="Description" Format="mm.dd.yy" WrapChar="""/> <ColumnFormat Name="Amount" Format="{0:##.00}"/> </ColumnFormats> </GLPayrollExportConfiguration>
XSLT:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:choose> <xsl:when test="override_segment_dynamic_labor_metric_code_CostNumber=' '"> <xsl:value-of select="override_segment_charged_dynamic_org_level_onsitedepartment"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="override_segment_dynamic_labor_metric_code_CostNumber"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
Thoughts?
I can’t repeat the error. However, it looks like your choose block tests will always fail and default to the <xsl:otherwise>
block.
Your path for the when
test is incorrect and will never select the attribute you want. For a dirty solution to get it to succeed you can use:
<xsl:when test="//Value[@Value = 'override_segment_dynamic_labor_metric_code_CostNumber'] = ''">
//
is generally a ham-fisted approach. In this case, //Value
selects all Value
nodes in the document.
@Value
selects an attribute of a node, which is the only place I could find your occurrence of ‘override_segment_dynamic_labor_metric_code_CostNumber’.
[]
the square brackets in Xpath contain predicates — or selection criteria.
Value[@Value = 'override_segment_dynamic_labor_metric_code_CostNumber']
returns the Value
node where the predicate is true.
note: I’m only using //
as an example of how it will succeed. You should really find the correct pathing for your situation.