simple(?) xml/xsl problem with xml from sql query

dSchwartz

Usenet Archive
Joined
Feb 18, 2004
Messages
10
Reaction score
0
I'm creating xml files from a dataset:
myDataSet.WriteXml(m_XmlFile, XmlWriteMode.IgnoreSchema);

and saving them to disk. Then i want to use the Xml control to format this xml with xsl stylesheet. here is part of my xml file created by the line above:

<?xml version="1.0" standalone="yes" ?>
<NewDataSet>
<articles>
<XML_F52E2B61-18A1-11d1-B105-0080F4...>
<sm_articles article_id="2" article_title="xxxx" ... /> <sm_articles article_id="3" article_title="yyyy" ... /> </XML_F52E.......> </articles> </NewDataSet>

Now in my xslt i can do a for-each select="//articles" and it will give me one item, but i'm not able to get past the <XML_.... tag. If i try select="//sm_articles" i don't get errors, like its returning an empty node.

so my question is what is the <XML_.... tag all about and how do i get past it? If i manually take that tag out then my Xml control works fine with my xsl stylesheet, but i have to build these xml files on the fly from sql server.

Thanks for your time!
 

Bryant Likes

Usenet Archive
Joined
Aug 29, 2000
Messages
5
Reaction score
0
dSchwartz said:
I'm creating xml files from a dataset:
myDataSet.WriteXml(m_XmlFile, XmlWriteMode.IgnoreSchema);

Where are you getting the XML in the DataSet from? That looks like the column header that is returned when you run a FOR XML Query.
 

dSchwartz

Usenet Archive
Joined
Feb 18, 2004
Messages
10
Reaction score
0
"Bryant Likes" wrote:
"dSchwartz" wrote:

> I'm creating xml files from a dataset:
> myDataSet.WriteXml(m_XmlFile, XmlWriteMode.IgnoreSchema);

Where are you getting the XML in the DataSet from? That looks like the column header that is returned when you run a FOR XML Query.

yes, its coming from a FOR XML database SQL server query. Is there a different way i should be converting a db query to valid xml? The naming of the xml elements are not really important, as long as they are consistent.
 

Chris Barber

Usenet Archive
Joined
Apr 12, 2002
Messages
404
Reaction score
0
This XML:

<?xml version="1.0" standalone="yes" ?>
<NewDataSet>
<articles>
<XML_F52E2B61-18A1-11d1-B105-0080F4>
<sm_articles article_id="2" article_title="xxxx" />
<sm_articles article_id="3" article_title="yyyy" />
</XML_F52E2B61-18A1-11d1-B105-0080F4>
</articles>
</NewDataSet>

With This XSL:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<sm_articles>
<xsl:apply-templates select="//sm_articles"/>
</sm_articles>
</xsl:template>
<xsl:template match="//sm_articles">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

Produces:

<?xml version="1.0" encoding="UTF-16"?>
<sm_articles>
<sm_articles article_id="2" article_title="xxxx" />
<sm_articles article_id="3" article_title="yyyy" />
</sm_articles>

with both MSXML4 and MSXML3.

I'm not sure where your error is but it's not evident with the XML you posted?

Perhaps there are some namespaces involved here?

Chris.

"dSchwartz" wrote:

"Bryant Likes" wrote:
...
"dSchwartz" wrote:

> I'm creating xml files from a dataset:
> myDataSet.WriteXml(m_XmlFile, XmlWriteMode.IgnoreSchema);

Where are you getting the XML in the DataSet from? That looks like the column header that is returned when you run a FOR XML Query.

yes, its coming from a FOR XML database SQL server query. Is there a different way i should be converting a db query to valid xml? The naming of the xml elements are not really important, as long as they are consistent.
 

dSchwartz

Usenet Archive
Joined
Feb 18, 2004
Messages
10
Reaction score
0
I know what the xml and xsl should produce, i think my problem is in the xml file that i've created. this is the file:
http://myweb.cableone.net/schwartz/1.xml

my question is about the <XML_F52E2B61-18A1-11d1-B105-00805F49916B> tag. xsl does not seem to know what to do with anything inside that, it returns empty nodes. It seems that everything inside that tag is treated as a string instead of real xml elements. if i manually remove that large tag, it all works great. Why is that tag there, am i missing some small step here?

and to be complete here is the code that produces that xml file:

string sql = "select * from sm_articles where newsletter_id=" + Convert.ToInt32(Request.QueryString["newsletter_id"].ToString) + " FOR XML AUTO";

string m_XmlFile = Server.MapPath("/smartmail/xml/" +
Request.QueryString["newsletter_id"].ToString + ".xml");

SqlCommand myCommand = new SqlCommand(sql, conn);

SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(sql, conn); DataSet myDataSet2 = new DataSet; mySqlDataAdapter.Fill(myDataSet2); conn.Close; myDataSet2.WriteXml(m_XmlFile);

Thanks for any ideas.

"Chris Barber" wrote:
I'm not sure where your error is but it's not evident with the XML you posted?

Perhaps there are some namespaces involved here?

Chris.
 

dSchwartz

Usenet Archive
Joined
Feb 18, 2004
Messages
10
Reaction score
0
if that link doesn't work try this one:

http://agentcrazydiamond.tripod.com/1.xml

sorry for the inconvenience, don't know whats wrong with my isp's web space.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,798
Members
249,594
Latest member
henrywalsh

Latest Threads

Top