InterviewSolution
| 1. |
Can An Element Or Attribute Name Contain A Colon? |
|
Answer» The XML 1.0 specification specifically reserves the colon character for use with XML Namespaces. No other use is compliant with XML 1.0. Therefore JDOM does not allow you to create element and attribute names that CONTAIN colons except when using namespaces. Furthermore, because of the way namespaces are implemented in JDOM, you cannot simply create an Element or Attribute with a fully qualified name like svg: title. That is you cannot do this: Element e = new Element ("svg: title"); INSTEAD you must split the two parts into a Namespace and a local name. This is the proper JDOM way to create an element in a namespace: Element e = new Element ("title", "svg", "http://www.w3.org/2000/svg"); The FIRST argument is the local name. The second argument is the prefix. The third argument is the namespace URI. If you're trying to create the xml: Lang and xml: space attributes use: Element e = new Element ("lang", Namespace.XML_NAMESPACE); The XML 1.0 specification specifically reserves the colon character for use with XML Namespaces. No other use is compliant with XML 1.0. Therefore JDOM does not allow you to create element and attribute names that contain colons except when using namespaces. Furthermore, because of the way namespaces are implemented in JDOM, you cannot simply create an Element or Attribute with a fully qualified name like svg: title. That is you cannot do this: Element e = new Element ("svg: title"); Instead you must split the two parts into a Namespace and a local name. This is the proper JDOM way to create an element in a namespace: Element e = new Element ("title", "svg", "http://www.w3.org/2000/svg"); The first argument is the local name. The second argument is the prefix. The third argument is the namespace URI. If you're trying to create the xml: Lang and xml: space attributes use: Element e = new Element ("lang", Namespace.XML_NAMESPACE); |
|