213 |
213 |
// }
|
214 |
214 |
try {
|
215 |
215 |
for (int event = parser.getEventType(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
|
|
216 |
System.out.println("event: " + event);
|
216 |
217 |
switch (event) {
|
|
218 |
|
217 |
219 |
case XMLStreamConstants.START_DOCUMENT:
|
218 |
220 |
if (encoding == null) { // if encoding is not specified,
|
219 |
221 |
encoding = parser.getCharacterEncodingScheme();
|
... | ... | |
231 |
233 |
writer.writeCharacters("\n");
|
232 |
234 |
break;
|
233 |
235 |
case XMLStreamConstants.NAMESPACE:
|
|
236 |
System.out.println("ADD NAMESPACE: " + parser.getPrefix() + " " + parser.getNamespaceURI());
|
234 |
237 |
this.Nscontext.addNamespace(parser.getPrefix(), parser.getNamespaceURI());
|
235 |
238 |
processNamespace();
|
236 |
239 |
break;
|
237 |
240 |
case XMLStreamConstants.START_ELEMENT:
|
238 |
241 |
firstElementStarted = true;
|
239 |
242 |
localname = parser.getLocalName();
|
|
243 |
|
|
244 |
for (int i = 0; i < parser.getNamespaceCount(); i++) {
|
|
245 |
Nscontext.addNamespace(parser.getNamespacePrefix(i), parser.getNamespaceURI(i));
|
|
246 |
}
|
240 |
247 |
// currentXPath.append(SLASH)
|
241 |
248 |
processStartElement();
|
242 |
249 |
break;
|
... | ... | |
371 |
378 |
|
372 |
379 |
protected void processStartElement() throws XMLStreamException, IOException {
|
373 |
380 |
String prefix = parser.getPrefix();
|
|
381 |
|
374 |
382 |
if (INCLUDE == localname && XI == prefix) {
|
375 |
383 |
processXInclude();
|
376 |
384 |
}
|
377 |
385 |
else {
|
378 |
|
if (prefix != null && prefix.length() > 0)
|
|
386 |
if (prefix != null && prefix.length() > 0) {
|
379 |
387 |
writer.writeStartElement(Nscontext.getNamespaceURI(prefix), localname);
|
380 |
|
else
|
|
388 |
}
|
|
389 |
else {
|
381 |
390 |
writer.writeStartElement(localname);
|
|
391 |
}
|
382 |
392 |
|
383 |
393 |
for (int i = 0; i < parser.getNamespaceCount(); i++) {
|
384 |
394 |
writer.writeNamespace(parser.getNamespacePrefix(i), parser.getNamespaceURI(i));
|
... | ... | |
488 |
498 |
|
489 |
499 |
public static void main(String[] args) {
|
490 |
500 |
try {
|
491 |
|
File input = new File("/home/mdecorde/xml/identity/test.xml");
|
492 |
|
File outputFile = new File("/home/mdecorde/xml/identity/test-copy.xml");
|
|
501 |
File input = new File("/home/mdecorde/runtime-rcpapplication.product/corpora/TXT/txm/TXT/0002 o2.xml");
|
|
502 |
File outputFile = new File("/home/mdecorde/runtime-rcpapplication.product/corpora/TXT/txm/TXT/0002 o2-out.xml");
|
493 |
503 |
if (!(input.exists() && input.canRead())) {
|
494 |
504 |
System.out.println("cannot found $input");
|
495 |
505 |
return;
|