Dom4j为XML文件要结点添加xmlns属性
问题:
根据google规定,在给自动给网站生成sitemap.xml的时候, 给根结点加如下属性时,遇到了麻烦
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
用很多方法,像addAttribute, addNamespce都不行
解决方法:
Document document = DocumentHelper.createDocument();
Element root = document.addElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
这样会自动生成xmlns属性
生成结果:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://***</loc>
<priority>0.5</priority>
<lastmod>2010-02-24</lastmod>
<changefreq>weekly</changefreq>
</url>
....
</urlset>
相关文档:
public sealed class XmlHelper
{
public static void Serialize<T>(T obj,string fileName)
{
TextWriter writer = new StreamWriter(fileName);
try
{
XmlSerializer ser = new XmlSerializer(typeof(T));
......
已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
&nb ......
按照名为"mydomain1.com"的 DomainName
属性对以下 XML 数据执行不区分大小写的搜索
<?xml version="1.0" ?>
<Domains>
<DomainName>Mydomain1.COM</DomainName>
</Domains>
MSXML 3.0 中 translate
的语法如下:
oXML.setProperty "SelectionLanguage&q ......
转贴地址:http://java.chinaitlab.com/advance/755393.html
现象描述:JDom输出Xml文件,当使用字符编码GBK时正常,而输出UTF-8时乱码。
完美的解决方法从辟谣开始:
1)JDOM是否生成UTF-8的文件与Format是否设置无关,只有输出其他字符编码才需要设置,见下面的注释。
& ......
1.books.html
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title ......