On Feb 18, 10:29 pm,
pauljlucas.removet...@removethistoo.mac.com (Paul J. Lucas)
wrote:
> I have code that builds a DOM using the Java org.w3c.dom
> API and it adds an extra attribute to one of the elements
> that I don't want. Not only that, the value it adds is
> wrong.
Disclaimer: last time I coded in Java was years ago. Still,
the problem seems obvious to me.
> Element xapDescElement = doc.createElementNS(
> "http://ns.adobe.com/xap/1.0/", "rdf:Description"
> );
Now, what are you doing here? You're your DOM API asking to
create a 'Description' element in
'http://ns.adobe.com/xap/1.0/' namespace, specifying the
'rdf' namespace prefix. Naturally, the result should look
as:
<rdf:Description xmlns:rdf="http://ns.adobe.com/xap/1.0/"/>
...which is precisely what you're getting.
> xapDescElement.setAttribute( "rdf:about", "" );
> xapDescElement.setAttribute( "xmlns:xap",
> "http://ns.adobe.com/xap/1.0/" );
First of all, language lawyers might correct me if get
something wrong, but those xmlns:foo thingies are not
attributes per se, or at least, they are extremely special
attributes. The proper term is namespace declaration nodes,
or something like that. So, I doubt setAttribute() is the
proper way of creating them. And even if does work, what
did you expect to happen? You declaring a namespace with
xap namespace prefix, but the element uses the rdf prefix
anyway.
So the problem is not in the API, the API does precisely
what you asked it to do. The problem is that you seem
either unsure about what you actually want, or you're
misunderstanding something about the way the XML namespaces
work.
Since I'm completely unfamiliar with XMP and RDF, I'm not
sure what you're doing wrong about your data, but I'd
recommend re-reading the specs on those formats (and
probably look up some examples to see how it actually
works).
> <x:xmpmeta xmlns:x="adobe:ns:meta/">
> <rdf:RDF
[quoted text clipped - 4 lines]
> </rdf:RDF>
> </x:xmpmeta>
Sure, it looks wrong, but it's what you asked for.
> There are two problems:
> 1. The second xmlns:rdf attribute shouldn't be there at
> all.
You're creating an element in that namespace using the rdf
prefix--of course it has to be declared, since the previous
declaration differs.
> 2. The value is wrong: it's the same as xmlns:xap. How
> did that happen?
It's the namespace you used in createElementNS().
--
roy axenov
Paul J. Lucas - 18 Feb 2007 21:38 GMT
In comp.text.xml roy axenov <r_axenov@mail.ru> wrote:
> On Feb 18, 10:29 pm,
> pauljlucas.removet...@removethistoo.mac.com (Paul J. Lucas)
> wrote:
> Disclaimer: last time I coded in Java was years ago. Still,
> the problem seems obvious to me.
[quoted text clipped - 6 lines]
> create a 'Description' element in 'http://ns.adobe.com/xap/1.0/'
> namespace ...
Oh yeah. It was just a silly mistake I couldn't see. Nothing beats
another pair of eyes. Thanks!
- Paul