EDN Admin
Well-known member
<p align=left><font face=Arial size=2>When I use this code it returns the XmlReader as {none}:</font>
<p align=left> <font size=2>
</font><font color="#0000ff" size=2>public</font><font size=2> </font><font color="#0000ff" size=2>static</font><font size=2> </font><font color="#008080" size=2>XmlReader</font><font size=2> _getTemplate(</font><font color="#0000ff" size=2>int</font><font size=2> id)
{
</font><font color="#0000ff" size=2>object</font><font size=2> o = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>XmlReader</font><font size=2> reader = </font><font color="#0000ff" size=2>null</font><font size=2>;
System.IO.</font><font color="#008080" size=2>MemoryStream</font><font size=2> msXml = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>XmlReaderSettings</font><font size=2> settings = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>StringReader</font><font size=2> s = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>SqlXml</font><font size=2> sql = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>XmlTextReader</font><font size=2> oXmlTextReader = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>SqlDataReader</font><font size=2> dr = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>SqlConnection</font><font size=2> sqlCnn = </font><font color="#008080" size=2>genSpHandler</font><font size=2>.sqlCnn_(ConnectionString);
</font><font color="#008080" size=2>SqlCommand</font><font size=2> sqlCmd = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>SqlCommand</font><font size=2>(</font><font color="#800000" size=2>"_getTemplate"</font><font size=2>, sqlCnn);
sqlCmd.CommandType = </font><font color="#008080" size=2>CommandType</font><font size=2>.StoredProcedure;
</font><font color="#0000ff" size=2>try </font><font size=2>
{
</font><font color="#008000" size=2>//add the value to set </font><font size=2>
sqlCmd.Parameters.Add(</font><font color="#800000" size=2>"@id"</font><font size=2>, </font><font color="#008080" size=2>SqlDbType</font><font size=2>.Int);
sqlCmd.Parameters[0].Value = id;
</font><font color="#0000ff" size=2>if</font><font size=2>(sqlCnn.State != </font><font color="#008080" size=2>ConnectionState</font><font size=2>.Open)
sqlCnn.Open();
</font><font color="#008000" size=2>// reader = sqlCmd.ExecuteXmlReader(); </font><font size=2>
o = sqlCmd.ExecuteScalar();
</font><font color="#0000ff" size=2>if</font><font size=2>(o != </font><font color="#0000ff" size=2>null</font><font size=2>)
{
oXmlTextReader = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>XmlTextReader</font><font size=2>(o.ToString(),
</font><font color="#008080" size=2>XmlNodeType</font><font size=2>.Document, context);
</font><font color="#008000" size=2>//s = new StringReader(o.ToString()); </font><font size=2>
</font><font color="#008000" size=2>//msXml = new System.IO.MemoryStream(System.Text.Encoding.Unicode.GetBytes(o.ToString())); </font><font size=2>
</font><font color="#008000" size=2>//sql = new SqlXml(msXml); </font><font size=2>
</font><font color="#008000" size=2>//reader = sql.CreateReader(); </font><font size=2>
}
}
</font><font color="#0000ff" size=2>catch</font><font size=2>(</font><font color="#008080" size=2>Exception</font><font size=2> exc)
{
log.Error(exc);
}
</font><font color="#0000ff" size=2>finally </font><font size=2>
{
</font><font color="#0000ff" size=2>if</font><font size=2>((dr != </font><font color="#0000ff" size=2>null</font><font size=2>) && (!dr.IsClosed)) dr.Close();
sqlCmd.Dispose();
sqlCnn.Close();
sqlCnn.Dispose();
}
</font><font color="#0000ff" size=2>return</font><font size=2> oXmlTextReader;
}
<p align=left>
<p align=left>Here the XSL:
<p align=left> <font color="#0000ff" size=2>
<?</font><font color="#800000" size=2>xml</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>version</font><font color="#0000ff" size=2>=</font><font size=2></font><font color="#0000ff" size=2>1.0</font><font size=2></font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>encoding</font><font color="#0000ff" size=2>=</font><font size=2></font><font color="#0000ff" size=2>UTF-8</font><font size=2></font><font color="#0000ff" size=2>?>
<</font><font color="#008080" size=2>xsl<img height=19 alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif" width=19>tylesheet</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>xmlns:xsl</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>http://www.w3.org/1999/XSL/Transform</font><font size=2>"</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>xmlns<img height=19 alt="Stick out tongue" src="http://forums.microsoft.com/MSDN/emoticons/emotion-4.gif" width=19>3</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>http://schemas.primavera.com/2006/API/5.0sp4/prmbo</font><font size=2>"</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>version</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>1.0</font><font size=2>"</font><font color="#0000ff" size=2>>
<</font><font color="#008080" size=2>xsl<img height=19 alt=Surprise src="http://forums.microsoft.com/MSDN/emoticons/emotion-3.gif" width=19>utput</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>method</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>xml</font><font size=2>"</font><font color="#0000ff" size=2>/>
<</font><font color="#008080" size=2>xsl<img height=19 alt="Stick out tongue" src="http://forums.microsoft.com/MSDN/emoticons/emotion-4.gif" width=19>aram</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>name</font><font color="#0000ff" size=2> =</font><font size=2></font><font color="#0000ff" size=2>Id_SUBP</font><font size=2></font><font color="#0000ff" size=2>>
<</font><font color="#008080" size=2>xsl:value-of</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>select</font><font color="#0000ff" size=2>=</font><font size=2></font><font color="#0000ff" size=2>p3:BusinessObjects/p3:ActivityCodeType[p3:Name="BANF: SUBP"]/p3<img height=19 alt=Surprise src="http://forums.microsoft.com/MSDN/emoticons/emotion-3.gif" width=19>bjectId</font><font size=2></font><font color="#0000ff" size=2>/>
...
<p align=left>
<p align=left>
<p align=left>Why is this?</font></font>
View the full article
<p align=left> <font size=2>
</font><font color="#0000ff" size=2>public</font><font size=2> </font><font color="#0000ff" size=2>static</font><font size=2> </font><font color="#008080" size=2>XmlReader</font><font size=2> _getTemplate(</font><font color="#0000ff" size=2>int</font><font size=2> id)
{
</font><font color="#0000ff" size=2>object</font><font size=2> o = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>XmlReader</font><font size=2> reader = </font><font color="#0000ff" size=2>null</font><font size=2>;
System.IO.</font><font color="#008080" size=2>MemoryStream</font><font size=2> msXml = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>XmlReaderSettings</font><font size=2> settings = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>StringReader</font><font size=2> s = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>SqlXml</font><font size=2> sql = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>XmlTextReader</font><font size=2> oXmlTextReader = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>SqlDataReader</font><font size=2> dr = </font><font color="#0000ff" size=2>null</font><font size=2>;
</font><font color="#008080" size=2>SqlConnection</font><font size=2> sqlCnn = </font><font color="#008080" size=2>genSpHandler</font><font size=2>.sqlCnn_(ConnectionString);
</font><font color="#008080" size=2>SqlCommand</font><font size=2> sqlCmd = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>SqlCommand</font><font size=2>(</font><font color="#800000" size=2>"_getTemplate"</font><font size=2>, sqlCnn);
sqlCmd.CommandType = </font><font color="#008080" size=2>CommandType</font><font size=2>.StoredProcedure;
</font><font color="#0000ff" size=2>try </font><font size=2>
{
</font><font color="#008000" size=2>//add the value to set </font><font size=2>
sqlCmd.Parameters.Add(</font><font color="#800000" size=2>"@id"</font><font size=2>, </font><font color="#008080" size=2>SqlDbType</font><font size=2>.Int);
sqlCmd.Parameters[0].Value = id;
</font><font color="#0000ff" size=2>if</font><font size=2>(sqlCnn.State != </font><font color="#008080" size=2>ConnectionState</font><font size=2>.Open)
sqlCnn.Open();
</font><font color="#008000" size=2>// reader = sqlCmd.ExecuteXmlReader(); </font><font size=2>
o = sqlCmd.ExecuteScalar();
</font><font color="#0000ff" size=2>if</font><font size=2>(o != </font><font color="#0000ff" size=2>null</font><font size=2>)
{
oXmlTextReader = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>XmlTextReader</font><font size=2>(o.ToString(),
</font><font color="#008080" size=2>XmlNodeType</font><font size=2>.Document, context);
</font><font color="#008000" size=2>//s = new StringReader(o.ToString()); </font><font size=2>
</font><font color="#008000" size=2>//msXml = new System.IO.MemoryStream(System.Text.Encoding.Unicode.GetBytes(o.ToString())); </font><font size=2>
</font><font color="#008000" size=2>//sql = new SqlXml(msXml); </font><font size=2>
</font><font color="#008000" size=2>//reader = sql.CreateReader(); </font><font size=2>
}
}
</font><font color="#0000ff" size=2>catch</font><font size=2>(</font><font color="#008080" size=2>Exception</font><font size=2> exc)
{
log.Error(exc);
}
</font><font color="#0000ff" size=2>finally </font><font size=2>
{
</font><font color="#0000ff" size=2>if</font><font size=2>((dr != </font><font color="#0000ff" size=2>null</font><font size=2>) && (!dr.IsClosed)) dr.Close();
sqlCmd.Dispose();
sqlCnn.Close();
sqlCnn.Dispose();
}
</font><font color="#0000ff" size=2>return</font><font size=2> oXmlTextReader;
}
<p align=left>
<p align=left>Here the XSL:
<p align=left> <font color="#0000ff" size=2>
<?</font><font color="#800000" size=2>xml</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>version</font><font color="#0000ff" size=2>=</font><font size=2></font><font color="#0000ff" size=2>1.0</font><font size=2></font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>encoding</font><font color="#0000ff" size=2>=</font><font size=2></font><font color="#0000ff" size=2>UTF-8</font><font size=2></font><font color="#0000ff" size=2>?>
<</font><font color="#008080" size=2>xsl<img height=19 alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif" width=19>tylesheet</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>xmlns:xsl</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>http://www.w3.org/1999/XSL/Transform</font><font size=2>"</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>xmlns<img height=19 alt="Stick out tongue" src="http://forums.microsoft.com/MSDN/emoticons/emotion-4.gif" width=19>3</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>http://schemas.primavera.com/2006/API/5.0sp4/prmbo</font><font size=2>"</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>version</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>1.0</font><font size=2>"</font><font color="#0000ff" size=2>>
<</font><font color="#008080" size=2>xsl<img height=19 alt=Surprise src="http://forums.microsoft.com/MSDN/emoticons/emotion-3.gif" width=19>utput</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>method</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>xml</font><font size=2>"</font><font color="#0000ff" size=2>/>
<</font><font color="#008080" size=2>xsl<img height=19 alt="Stick out tongue" src="http://forums.microsoft.com/MSDN/emoticons/emotion-4.gif" width=19>aram</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>name</font><font color="#0000ff" size=2> =</font><font size=2></font><font color="#0000ff" size=2>Id_SUBP</font><font size=2></font><font color="#0000ff" size=2>>
<</font><font color="#008080" size=2>xsl:value-of</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>select</font><font color="#0000ff" size=2>=</font><font size=2></font><font color="#0000ff" size=2>p3:BusinessObjects/p3:ActivityCodeType[p3:Name="BANF: SUBP"]/p3<img height=19 alt=Surprise src="http://forums.microsoft.com/MSDN/emoticons/emotion-3.gif" width=19>bjectId</font><font size=2></font><font color="#0000ff" size=2>/>
...
<p align=left>
<p align=left>
<p align=left>Why is this?</font></font>
View the full article