我正在尝试转换一些 XML [由 sql 查询返回,例如 SELECT ... FOR XML RAW('EmailData'),ROOT('Emails'),type] 但无论出于何种原因,这行给我带来了问题:
<Emails>
<EmailData ID="370" C_ID="93" Co_ID="019" MemberName="Twin Cities Orthopedics – Savage" Commit_Program_ID="92" SubmittedBy="9175" AccountExecInfo="Jessica Cooley, jcooley@cc.com" PortfolioExecInfo="Seth Bull, 000.581.5006, sbulling@CCDD.com" SupplierRepInfo="Matt Matts, 000.000.4236 Ext-37, Matt.Matts@ker.com" MemberInfoLink="https://nf.CCDD.com/asp/memberinfo.asp?memid=7893&co=019" DocumentLink="https://nf.CCDD.com/asp/maintanance.asp?doc_id=630" TermsAndCondLink="https://nf.CCDD.com/TermsAndConditions.asp?CPID=92" Doc_Source_ID="BTM" SubmittedByInfo="Automated Tier Update" />
</Emails>
Cuplrit 似乎是 MemberName 属性值......因为当我返回一个空字符串而不是上述值时,我没有得到异常。您是否看到任何无效字符?'-' 是 xml 的无效字符吗?
我的 XSL 转换代码:
public static SqlXml Transform(SqlXml inputDataXML, SqlXml inputTransformXML)
{
try
{
MemoryStream memoryXml = new System.IO.MemoryStream();
XslCompiledTransform xslt = new XslCompiledTransform();
XmlReader output = null;
xslt.Load(inputTransformXML.CreateReader());
// Output the newly constructed XML
XmlTextWriter outputWriter = new XmlTextWriter(memoryXml, System.Text.Encoding.Default);
xslt.Transform(inputDataXML.CreateReader(), null, outputWriter, null);
memoryXml.Seek(0, System.IO.SeekOrigin.Begin);
output = new XmlTextReader(memoryXml);
return new SqlXml(output);
}
catch(Exception ex)
{
byte[] byteArray = Encoding.ASCII.GetBytes( "<error>" + ex.ToString() + "</error>");
MemoryStream stream = new MemoryStream( byteArray );
XmlReader reader = new XmlTextReader(stream);
SqlXml x = new SqlXml(reader);
return x;
}
}