Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10855
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news-peer.in.tum.de!news.belwue.de!newsout01.versatel.de!newsin01.versatel.de!news.versatel.de!not-for-mail |
|---|---|
| From | Michael Jung <miju@golem.phantasia.org> |
| Newsgroups | comp.lang.java.programmer |
| Subject | xml:id |
| Date | Sun, 18 Dec 2011 21:33:38 +0100 |
| Lines | 60 |
| Message-ID | <87wr9t1uxp.fsf@golem.phantasia.org> (permalink) |
| NNTP-Posting-Host | i59f77ed2.versanet.de |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-Trace | news01.versatel.de 1324240418 22304 89.247.126.210 (18 Dec 2011 20:33:38 GMT) |
| X-Complaints-To | abuse@versatel.de |
| NNTP-Posting-Date | Sun, 18 Dec 2011 20:33:38 +0000 (UTC) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:T3j+FGJoid1VQF9eYi1VEaaHRa8= |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10855 |
Show key headers only | View raw
I have a problem with transfering xml:ids from one document to another,
sample code is attached. Somehow the id attribute gets lost. Am I doing
something wrong, missing something, or is this a bug in the XML libs (I
use the ones supplied with the standard JDK)? Maybe this is a "feature"?
It is rather annoying if this doesn't work, since it forces me to to
travers the tree and do id handling myself.
The code produces the same output under OpenJDK, Sun's JDK 1.6 and 1.5:
: [elem: null]
: [elem: null]
: null
=== SimleTest.java ===
import java.io.File;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class SimpleTest {
public static void main(String[] a) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
Document parsed = docBuilder.parse(new File("test.xml"));
System.out.println(parsed.getElementById("x"));
Document parsed2 = docBuilder.parse(new File("test.xml"));
Element el = parsed.getElementById("x");
el.setAttribute("id", "x2");
System.out.println(parsed.getElementById("x2"));
// I have tried importNode as well, that even loses the "isId"
// property of the "id" tag.
parsed2.adoptNode(el);
// I definitely want to avoid the next call, since I'd need to
// traverse in production code. But it is useless anyway.
el.setIdAttribute("id", true);
System.out.println(parsed2.getElementById("x2"));
}
}
=== test.xml ===
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./test.xsd">
<elem id="x"/>
</test>
=== test.xsd ===
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="test">
<xs:complexType>
<xs:choice>
<xs:element name="elem">
<xs:complexType>
<xs:attribute name="id" type="xs:ID" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
xml:id Michael Jung <miju@golem.phantasia.org> - 2011-12-18 21:33 +0100
Re: xml:id Lee Fesperman <firstsql@gmail.com> - 2011-12-19 00:24 -0800
Re: xml:id Michael Jung <miju@golem.phantasia.org> - 2011-12-19 10:27 +0100
Re: xml:id Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-12-19 11:25 -0400
Re: xml:id Michael Jung <miju@golem.phantasia.org> - 2011-12-19 19:06 +0100
Re: xml:id Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-12-19 17:26 -0400
Re: xml:id Michael Jung <miju@golem.phantasia.org> - 2011-12-20 22:54 +0100
csiph-web