Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Just two quick questions

Reply
Thread Tools

Just two quick questions

 
 
Horny Porno-thologist
Guest
Posts: n/a
 
      01-27-2004
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



 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      01-27-2004
In article <401678e8$(E-Mail Removed)>,
Horny Porno-thologist <(E-Mail Removed)> 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!
 
Reply With Quote
 
 
 
 
Paul Lee
Guest
Posts: n/a
 
      01-27-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two quick questions JS Java 7 01-18-2006 11:55 AM
two quick questions tascienu@ecoaches.com XML 1 03-13-2005 09:45 PM
Two quick questions about my band-related website Geoff Hague HTML 5 07-15-2004 05:04 AM
two quick questions Steve 'Wacko' Computer Support 6 09-27-2003 04:11 AM
two quick questions Elaine Jackson Python 7 08-13-2003 10:35 PM



Advertisments