On 03/17/2011 09:23 AM, Philippe Nobili wrote:
>
>> This wouldn't be useful because a newly inserted element would get its
>> automatic ID as soon as the document is validated/saved. (Something
>> like "???" would be of course automatically replaced.)
>>
>> In a nutshell, we can guarantee that with such validateHook, after a
>> document is validated/saved, each element would have its own, unique,
>> automatic ID matching exactly the text pattern you want.
>>
>> Such validateHook is quite easy to write in Java.
>>
>> References:
>>
>> * http://www.xmlmind.com/xmleditor/_distrib/doc/configure/validateHook.html
>>
>> * http://www.xmlmind.com/xmleditor/_distrib/doc/dev/validatehook.html
>>
> Dear Mr. Shafie,
>
> We did as you suggested, which is indeed an easy way to process the
> authored document. We wondered what would be the best way to
> automatically generate missing IDs (e.g. those equal to '???').
>
Test the value of the id attribute using XMLText.isNCName and replace
all values which are not NCNames. ("???" is of course not an NCName.)
See
http://www.xmlmind.com/xmleditor/_distrib/doc/api/com/xmlmind/util/XMLText.html#isNCName%28java.lang.String%29
> We hoped to find a method similar to 'generate-id(.)' function call in
> the XXE Java API (e.g. in , but did not see any. We thought XNode was
> the place where to start to look for a solution; how would you advise
> us to achieve this ?
>
--> Do not use XNodes at all. XNodes are not the native DOM of XMLmind
XML Editor. XNodes are just needed to implement XPath.
See http://www.xmlmind.com/xmleditor/_distrib/doc/dev/dom.html
See http://www.xmlmind.com/xmleditor/_distrib/doc/dev/xpath.html#d0e1723
--> There is no public API which implements something similar to
'generate-id(.)'. The private static method which implements this is
rather crude:
---
private static int uniqueId = 0;
private static final String generateUniqueId() {
StringBuilder buffer = new StringBuilder();
buffer.append("___");
buffer.append(Long.toString(System.currentTimeMillis(),
Character.MAX_RADIX));
buffer.append(".");
buffer.append(Integer.toString(uniqueId++, Character.MAX_RADIX));
return buffer.toString();
}
---
You can easily invent your own one, for example, using java.util.UUID.
See http://download.oracle.com/javase/1.5.0/docs/api/java/util/UUID.html
--
XMLmind XML Editor Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xmleditor-support