0

I have to create a XML namespace which contains a URL. As result i get the INVALID_CHARACTER for XML error. So i tried to put the URL in a string first - same result. When i try to put the URL in a URL variable and try to add it after the elementtext:

Element rootElement = doc.createElement("esb"+ url);

it wont work because its not a string.

The url is like: xmlns:tns="http://www.xxxxxxx-xxxxxxxxxx.xx/xxx-xxx-xxxx"

I also tried to replace the " with &quot... Does someone here has an idea how i can use the URL as Namespace?

Edit:/ I figured out that the / characters are causing the problem - but the internet says - / is a valid character... so is java causing the problem here? (I use eclipse for coding)

René
  • 1
  • 3
  • Possible duplicate question: http://stackoverflow.com/questions/4328711/read-url-to-string-in-few-lines-of-java-code – JBiss Nov 10 '15 at 09:30
  • http://stackoverflow.com/questions/11798216/setting-namespace-attributes-on-an-element – Shailendra Nov 10 '15 at 09:33
  • `xmlns:ts="http://.....'"` is not a URL. It is a namespace declaration that binds the prefix ts to a URI. Whatever DOM interfaces you use for this, you will need to present each part separately. Since you're obviously fairly new to DOM, have you considered using one of the alternatives, like JDOM2 or XOM? They are infinitely more friendly, especially when it comes to namespaces. – Michael Kay Nov 10 '15 at 15:18

1 Answers1

0

You shouldn't concatenate the url with the name of the element to create.

As far as I remember, you should use the method createElementNS(String namespaceURI, String qualifiedName).

In your case this should become something like:

Element rootElement = doc.createElementNs("http://www.x...", "tns:esb");
C.Champagne
  • 5,381
  • 2
  • 23
  • 35