开发者

How can I merge two XML files in Perl?

开发者 https://www.devze.com 2022-12-16 22:49 出处:网络
UPDATE: Let me go into more details (as requested) I have 2 Perl files, the first one generates a XML request/开发者_C百科POST (No file is made).

UPDATE:

Let me go into more details (as requested)

I have 2 Perl files, the first one generates a XML request/开发者_C百科POST (No file is made). The second file is new and intended to add another element inside of the XML on certain conditions. The problem I'm having is the first file already checks for the conditions but the second file is needed to generate the new XML. How do I add the XML to the first file from the second file?

something like this:

(File #3 uses File #1)

use file1

my $xml = File1->new();

# Set some properties

# Now adding XML from file #2
my $addXML = File2->new();

# Set some more properties

# File1 needs to check if the XML or Object from File2 
# exists to add the XML to File1, else throw error.

I hope this helps and sorry for the first post.


I'm assuming here that both "File1" and "File2" are purely object-oriented modules, meaning for this purpose that they do not maintain global state and only support class methods for creating objects and object methods for performing actions on those objects.

In this case, I'd put the checking logic in your main program, not in the File1 module, and write it like so:

if ($addXML->hasObjectImLookingFor) {
     $xml->add($addXML->getObjectImLookingFor);
} else {
     die "File 2 does not contain object I'm looking for";
}

I'm sorry this is vague, but honestly, so is your question. If you can actually give us a small sample of complete Perl code (I understand it can't be your real code, but just a small dummy module that illustrates the behavior) that might help.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号