Just two quick questions

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
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Horny Porno-thologist said:
What I want to do is to insert my second XML file between the tags so that it reads:
<ATO_RawXML>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> (XML data in here...snipped for brevity)
</ATO_RawXML>

You can't do this. An xml declaration may only occur at the start of a document. There is no way to have it embedded inside another document.

-- Richard
 

Paul Lee

Usenet Archive
Joined
Jul 19, 2001
Messages
13
Reaction score
0
Thanks Richard,

Now all I have to do is solve the second problem - the tag being replaced. I can see why it is doing this, but I don't know how to circumvent the problem, unless it requires regenerating the "missing" tag.... can anyone suggest a very easy way of doing this?

Best wishes

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,802
Members
249,594
Latest member
henrywalsh

Latest Threads

Top