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>
相关文档:
import java.io.StringWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xerces.dom.DOMImplementationImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;
import org.apache.xml. ......
两种方法:
其一,使用 SelectNodes 的方法;以下例子为使用此方法的处理。
其二,使用 XQuery 的方法。
''' <summary>
''' 从 XML 文件中取得对应ID 的语言值
''' </summary>
''' <param name="textID">输入的ID< ......
1.读取XML文件的类:
public class XMLUtils {
private final String DB_XML_FILE = "/XMLSetting.xml";
public Properties getPropertiesfromXML() {
URL url = XMLUtils.class.getResource(dBXMLFILE);
URI uri;
try {
uri = url.toURI();
InputSource xmlfile = new InputSource(uri.g ......
一个C# xml 序列化错误
事发现场:
xml序列化的数据中存储的节点数据是
<Module>536870912</Module> (xml文件中)
对应的类属性是
public short Module { get; set; } (C#类中)
序列化的代码:
public static FMDSTimeSeriesDefinitio ......