|
 |
|
อยากสอบถามเรื่องการตรวจสอบ file xml ครับมันผิด XML namespace is wrong แก้อย่างไรดีครับ |
|
 |
|
|
 |
 |
|
แล้ว format ที่ถูกมันเขียนยังไงอ่ะ
|
 |
 |
 |
 |
Date :
2013-01-18 16:54:27 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TestTest();
}
}
static DataTable Table()
{
clsDatabase clsDB = new clsDatabase();
DataTable table = new DataTable("url");
table.Columns.Add("loc", typeof(string));
table.Rows.Add("http://www.test1.com/");
table.Rows.Add("http://www.test1.com/new.asp");
return table;
}
private void TestTest()
{
DataSet set = new DataSet();
set.Tables.Add(Table());
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Server.MapPath("sitemap.xml"), System.Text.Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xsi", "schemaLocation", null, "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd");
set.WriteXml(writer);
writer.WriteEndDocument();
writer.Close();
}
ตอนรันจะได้
Code (XML)
<?xml version="1.0" encoding="UTF-8"?>
-<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<NewDataSet xmlns="">
-<url>
<loc>http://www.test.com/</loc>
</url>
-<url>
<loc>http://www.test.com/new.asp</loc>
</url>
</NewDataSet>
</urlset>
แบบฟรอมจะถูกแล้วครับติดตรง -<NewDataSet xmlns=""></NewDataSet> มันออกมาเองอ่ะครับไม่รู้จะตัดยังไง ถ้าไม่มีอันนี้ ลองตรวจสอบดูแล้วผ่านเลยครับ ถ้ารู้บอกทีครับ T_T ขอบคุณล่วงหน้าครับ
|
ประวัติการแก้ไข 2013-01-18 18:07:07
 |
 |
 |
 |
Date :
2013-01-18 18:06:02 |
By :
yatard |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
DataTable dt = new DataTable();
dt.Columns.Add("loc", typeof(string));
dt.Rows.Add("http://www.test1.com/");
dt.Rows.Add("http://www.test1.com/new.asp");
WriteSiteMapXml(string.Format("{0}\\sitemap.xml", Application.StartupPath), "url", dt);
Code (C#)
public void WriteSiteMapXml(string xmlPath, string tagName, DataTable dtData)
{
if (File.Exists(string.Format("{0}\\sitemap.xml", Application.StartupPath)))
File.Delete(string.Format("{0}\\sitemap.xml", Application.StartupPath));
XmlTextWriter writer = new System.Xml.XmlTextWriter(xmlPath, System.Text.Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xsi", "schemaLocation", null, "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd");
writer.Indentation = 0;
writer.Formatting = Formatting.Indented;
foreach (DataRow dr in dtData.Rows)
{
writer.WriteStartElement(tagName);
foreach (DataColumn dc in dtData.Columns)
{
writer.WriteElementString(dc.ColumnName, (dr[dc.ColumnName] != null) ? dr[dc.ColumnName].ToString() : string.Empty);
}
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
if (writer != null)
{
writer.Flush();
}
if (writer.WriteState != WriteState.Closed)
{
writer.Close();
}
}
|
 |
 |
 |
 |
Date :
2013-01-21 09:45:34 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|