Horny Porno-thologist
Usenet Archive
- Joined
- Jan 27, 2004
- Messages
- 2
- Reaction score
- 0
Dear everyone,
I managed to get most of my code (nesting documents etc.) worked out, but there are a few niggles.
The first one is as follows:
My first document is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <WfMessage> <ATO_ATO> <ATO_FileLoadedIntoSystem>No</ATO_FileLoadedIntoSystem> <ATO_RawXML>XML DATA HERE</ATO_RawXML> </ATO_ATO> </ProcInstInputData> </ProcessTemplateExecute> </WfMessage>
What I want to do is to insert my second XML file between the tags so that it reads:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <WfMessage> <ATO_ATO> <ATO_FileLoadedIntoSystem>No</ATO_FileLoadedIntoSystem> <ATO_RawXML> <?xml version="1.0" encoding="UTF-8" standalone="yes"?> (XML data in here...snipped for brevity) </ATO_RawXML> </ATO_ATO> </ProcInstInputData> </ProcessTemplateExecute> </WfMessage>
(By the way, I do need the second root in the nested document!) I've come up with some code that comes up with the following XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <WfMessage> <ATO_ATO> <ATO_FileLoadedIntoSystem>No</ATO_FileLoadedIntoSystem> (data in here...snipped for brevity) // TAGS AND ROOT MISSING !!! </ATO_ATO> </ProcInstInputData> </ProcessTemplateExecute> </WfMessage>
Which is nearly what I need when I use the following code:
ATO_document = builder.parse( "D:\\ATO.xml" );
XML_document = builder.parse( "D:\\XML.xml" );
NodeList replacedNodeList = XML_document.getElementsByTagName("ATO_RawXML"); Node foundnode = replacedNodeList.item(0); if ( foundnode != null ) { Node modfiedReplacedDocument = replaceNode(XML_document, ATO_document, foundnode);} else { // error message here. } } and replaceNode is defined as follows:
public static Node replaceNode(Document replacedDocument, Document replacingDocument, Node replacedNode) { //Create a documentFragment of the replacingDocument
DocumentFragment docFrag = replacingDocument.createDocumentFragment; Element rootElement = replacingDocument.getDocumentElement; docFrag.appendChild(rootElement);
//Import docFrag under the ownership of replacedDocument
Node replacingNode =
((replacedDocument).importNode(docFrag, true));
//In order to replace the node need to retrieve replacedNode's parent
Node replaceNodeParent = replacedNode.getParentNode;
replaceNodeParent.replaceChild(replacingNode, replacedNode); return replacedDocument; }
I've tried using insertBefore functions in the replaced document to artificially recreate the <ATO_RawXML> tags, but the code grumbles that the parent element is missing. I'm sure a solution is very simple but I am losing my hair over this. Can anyone suggest anything (other than a lotion to keep my hair in) ?
Best wishes
Paul
I managed to get most of my code (nesting documents etc.) worked out, but there are a few niggles.
The first one is as follows:
My first document is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <WfMessage> <ATO_ATO> <ATO_FileLoadedIntoSystem>No</ATO_FileLoadedIntoSystem> <ATO_RawXML>XML DATA HERE</ATO_RawXML> </ATO_ATO> </ProcInstInputData> </ProcessTemplateExecute> </WfMessage>
What I want to do is to insert my second XML file between the tags so that it reads:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <WfMessage> <ATO_ATO> <ATO_FileLoadedIntoSystem>No</ATO_FileLoadedIntoSystem> <ATO_RawXML> <?xml version="1.0" encoding="UTF-8" standalone="yes"?> (XML data in here...snipped for brevity) </ATO_RawXML> </ATO_ATO> </ProcInstInputData> </ProcessTemplateExecute> </WfMessage>
(By the way, I do need the second root in the nested document!) I've come up with some code that comes up with the following XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <WfMessage> <ATO_ATO> <ATO_FileLoadedIntoSystem>No</ATO_FileLoadedIntoSystem> (data in here...snipped for brevity) // TAGS AND ROOT MISSING !!! </ATO_ATO> </ProcInstInputData> </ProcessTemplateExecute> </WfMessage>
Which is nearly what I need when I use the following code:
ATO_document = builder.parse( "D:\\ATO.xml" );
XML_document = builder.parse( "D:\\XML.xml" );
NodeList replacedNodeList = XML_document.getElementsByTagName("ATO_RawXML"); Node foundnode = replacedNodeList.item(0); if ( foundnode != null ) { Node modfiedReplacedDocument = replaceNode(XML_document, ATO_document, foundnode);} else { // error message here. } } and replaceNode is defined as follows:
public static Node replaceNode(Document replacedDocument, Document replacingDocument, Node replacedNode) { //Create a documentFragment of the replacingDocument
DocumentFragment docFrag = replacingDocument.createDocumentFragment; Element rootElement = replacingDocument.getDocumentElement; docFrag.appendChild(rootElement);
//Import docFrag under the ownership of replacedDocument
Node replacingNode =
((replacedDocument).importNode(docFrag, true));
//In order to replace the node need to retrieve replacedNode's parent
Node replaceNodeParent = replacedNode.getParentNode;
replaceNodeParent.replaceChild(replacingNode, replacedNode); return replacedDocument; }
I've tried using insertBefore functions in the replaced document to artificially recreate the <ATO_RawXML> tags, but the code grumbles that the parent element is missing. I'm sure a solution is very simple but I am losing my hair over this. Can anyone suggest anything (other than a lotion to keep my hair in) ?
Best wishes
Paul