我正在使用java创建一个sitemap xml。
Element img = doc.createElement("image:image");
我得到了一个异常:
org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.
关于如何创建元素有什么建议吗?
发布于 2013-04-09 19:58:45
我认为您应该使用XML名称空间。有关如何做到这一点,请参阅此问题:Creating an XML document using namespaces in Java
发布于 2013-04-09 19:51:15
在此元素名称"image:image"
中,此:
不是有效的编写器。
编辑
Reference link
Best Naming Practices for XML Element Name
Make names descriptive. Names with an underscore separator are nice: <first_name>, <last_name>.
Names should be short and simple, like this: <book_title> not like this: <the_title_of_the_book>.
Avoid "-" characters. If you name something "first-name," some software may think you want to subtract name from first.
Avoid "." characters. If you name something "first.name," some software may think that "name" is a property of the object "first."
Avoid ":" characters. Colons are reserved to be used for something called namespaces (more later).
XML documents often have a corresponding database. A good practice is to use the naming rules of your database for the elements in the XML documents.
Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software vendor doesn't support them.
https://stackoverflow.com/questions/15900829
复制相似问题