473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Just two quick questions

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

Jul 20 '05 #1
2 1573
In article <40********@baen1673807.greenlnk.net>,
Horny Porno-thologist <pa********@aesystems.com> wrote:
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
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #2
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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Elaine Jackson | last post by:
Two quick newbie questions: 1) Does Python have passing-by-reference? 2) In ordinary parlance, "deep" implies "shallow" but not conversely. In the Python "copy" module (if I understand...
1
by: YT | last post by:
Couple of quick ASP (3.0) Cookie questions: 1/ I'm using a cookie in my asp script to place cookies (within a key) so my code looks like: Response.Cookies( "quoteform" )( "name" ) = Session(...
8
by: Dutchy | last post by:
Dear reader, In an attempt to obtain the path to the quick-launch-folder in order to create a shortcut to my application-updates during installation , I thought to: 1- check if quick launch...
0
by: netguru7575 | last post by:
All Quick Test Professional (QTP) FAQs QuickTest Professional (QTP) Questions and Answers Part # 1 http://softwareqatestings.com/content/view/188/38/
6
by: SuperDuper | last post by:
Just a few quick questions. 1) How would I count the length of words in 5 certain strings. SomeString.s1, SomeString.s2, etc.. 2) How to compute the average word length? 3) How to compute...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.