Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsProblem during replacing element from one schema to another schema using DOM
https://www.eclipse.org/forums/index.php/mv/msg/190441/604184/#msg_604184
I am trying to replace an element from one schema(source) to another
schema(target) schema using DOM APIs as below :
and the replacement is not happening properly.
File file1 = new File(sourceLoc);
File file2 = new File(targetLoc);
final ResourceSet resourceSet = new ResourceSetImpl();
final Resource res1 =
resourceSet.getResource(URI.createURI(file1.toURI().toString ()), true);
final Resource res2 =
resourceSet.getResource(URI.createURI(file2.toURI().toString ()), true);
Element element = srcComponent.getElement();
if (element != null) {
final Node newComponent =
targetSchema.getDocument().importNode(srcComponent.getElemen t(), true);
targetSchema.getElement().replaceChild(newComponent,
oldComponent.getElement());
targetSchema.getDocument().normalizeDocument();
}
targetSchema.validate();
final Collection<XSDDiagnostic> diag = targetSchema.getAllDiagnostics();
if (diag != null && !diag.isEmpty()) {
for (final XSDDiagnostic dia : diag) {
System.out.println(dia.getMessage());
}
}
Resource resource = targetSchema.eResource();
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
public void selectionChanged(IAction action, ISelection selection) {
}
------------------------------------------------------------ ------
Validation falis with below message
------------------------------------------------------------ ------
XSD: Type reference 'tns1#simple1' is unresolved, which is true as
replacechild() method should have defined "tns1" in element ?
Am i doing something wrong or is there any other way to do this.
--
Thanks and Regards,
Bhuvan Mehta]]>Bhuvan Mehta2009-05-15T04:29:27-00:00