XML для вывода на Perl не соответствует ожиданиям - PullRequest
0 голосов
/ 03 декабря 2018

По какой-то причине приведенный ниже код создает XML, который я не ожидаю.В основном, следующие 4 строки кода:

my $AddStockDate= {
    path => 'dueToStockDate',
    Value => $EXPDATE };

my $AddOrderQty= {
    path => 'releaseQuantity',
    Value => $ORDQTY };

my $AddReleaseId= {
    path => 'userFieldAmount1',
    Value => $RELEASE };

my $AddPartNum= {
    path => 'item',
    Value => $PARTNBR };

$AddXML->{'System-Link'}{Request}{Create}{DomainEntity}{Property}[0] = $AddStockDate;
$AddXML->{'System-Link'}{Request}{Create}{DomainEntity}{Property}[1] = $AddOrderQty;
$AddXML->{'System-Link'}{Request}{Create}{DomainEntity}{Property}[2] = $AddReleaseId;
$AddXML->{'System-Link'}{Request}{Create}{DomainEntity}{Property}[3] = $AddPartNum;

Создайте следующий XML:

<Property Value="20181207" path="dueToStockDate"/>
<Property Value="4" path="releaseQuantity"/>
<Property Value="9150021" path="userFieldAmount1"/>
<Property Value="04-13165-02" path="item"/>

Действительно, «Значение» должно быть тегом, а не атрибутом, как дляКлючевой элемент.так почему же он рассматривается как атрибут для этих 4 строк?

Вот весь раздел кода для контекста:

#!/usr/bin/perl

########################################################################
## Define Perl Packages to Use
########################################################################
use POSIX;
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Request::Common;
use XML::Simple;
use XML::Smart;
use Net::SMTP;

########################################################################
## Define Local Variables
########################################################################
my $lastSeqNum;
my $result;
my ($error, $errStr);
my $storedSeqNum = 0;

my ($var, $val, $configLine);
my ($tmpMon, $tmpYear);
my ($db, $DSN, $sql, $data, $count);

my ($CELLLOC, $CELLCLR,  $SWONBR,  $PONUMBR,  $SWOLINE, $POLINE,   $CELLPID,
    $EXPDATE, $ISSUESRC, $RELEASE, $PARTNAME, $BARCODE, $REVISION, $CELLNAM,
    $TRACKING_NUMBER,
    $PARTNBR, $ORDQTY,   $RELEVT,  $ERRMSG,   $ISSTYPE, $seqNum,     $ERPVNUM);

my ($sigUser, $sigPass, $SQLUser, $SQLPass,
    $smtp, $smtpServer, $mailTo, $mailCC, $mailFrom,
    $confirmIssue, $issueDependent , $SUPPLIER_MATCH);

########################################################################
## Local scripts directory for the Windows machine
########################################################################
$scriptDir = ".";
$agentsDir = "$scriptDir";
$logsDir   = "$scriptDir/logfiles";
#
########################################################################
# Open a new Log file for todays processing
########################################################################
our ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$tmpMon = $mon + 1;
$tmpYear = $year + 1900;
$tmpMon = "0" . $tmpMon if ($tmpMon < 10);
$mday = "0" . $mday if ($mday < 10);
$log_timestamp = localtime(time);
$script_start = time;
my $logFileName = "$0.$tmpYear$tmpMon$mday.log";

########################################################################
## Check to see if log file exists, if already exists concatenate
########################################################################
open(LOGF, ">>$logsDir/$logFileName") || die "Cannot open logfile: $!";
LOGF->autoflush(1);
print LOGF "\n{INFO}  [" . localtime(time) . "] $0 process STARTED\n";

    ## Parse the response for values you will need for subsequent SystemLink calls
    my $SessionHandle = "FakeSession";
    my $workHandle = "WorkHandle";
    my $QueryStatus = "true";
    print LOGF "{DEBUG} [" . localtime(time) . "] \tSession Handle: $SessionHandle\n";
    print LOGF "{DEBUG} [" . localtime(time) . "] \tWork Handle: $workHandle\n";
    print LOGF "{DEBUG} [" . localtime(time) . "] \tQuery Status: $QueryStatus\n";

    ## Now verify whether or not the actual order query was successful or not.  If not, send an error email and move on to next Release
    if($QueryStatus ne 'true') { 
        print LOGF "{ERROR} [" . localtime(time) . "] XML QUERY Post to SystemLink for Release: $RELEASE status is: Query Failure\n";
        print LOGF "{ERROR} [" . localtime(time) . "] XML QUERY Post to SystemLink for Release: $RELEASE COMPLETED with ERRORS. Skipping.\n";
#No SystemLink,Ignore Error#        ErrorHandler("NON-FATAL", "S1002", undef, "SystemLink QUERY XML Post Query Failure", $RELEASE, "$xml_filename");
    }

    my $SLOrderNum = "OrderNum";
    my $SLLineNum = "LineNum";
    print LOGF "{DEBUG} [" . localtime(time) . "] \tOrder Number: $SLOrderNum\n";
    print LOGF "{DEBUG} [" . localtime(time) . "] \tLine Number: $SLLineNum\n";

    if($SLOrderNum eq '') { 
        print LOGF "{ERROR} [" . localtime(time) . "] XML QUERY Post to SystemLink for Release: $RELEASE status is: No Open Order Found\n";
        print LOGF "{ERROR} [" . localtime(time) . "] XML QUERY Post to SystemLink for Release: $RELEASE COMPLETED with ERRORS. Skipping.\n";
#No SystemLink,Ignore Error#        ErrorHandler("NON-FATAL", "S1003", undef, "SystemLink QUERY XML Post No Open Order Found", $RELEASE, "$xml_filename"); 
    }

    ## Now that we've verified all the Order and Line information, we need to create the actual MAPICS order
    print LOGF "{DEBUG} [" . localtime(time) . "] \tBuilding CREATE XML Request STARTED\n";
    my $AddXML = XML::Smart->new();
    my $AddRequest = {
        sessionHandle => $SessionHandle,
        workHandle => $workHandle,
        broker => 'EJB',
        maxIdle => '900000'};
    $AddXML->{'System-Link'}{Request} = $AddRequest;

    my $AddCreate = {
        name => 'createObject_PurchaseOrderItemRelease',
        domainClass => 'com.mapics.pm.PoItemRelease'};
    $AddXML->{'System-Link'}{Request}{Create} = $AddCreate;
    $AddXML->{'System-Link'}{Request}{Create}{ApplyTemplate} = '(none)';

    my $AddOrder = {
        path => 'order',
        Value => $SLOrderNum };

    my $AddLine= {
        path => 'line',
        Value => $SLLineNum };


    $EXPDATE = "2018-01-01";
    my $AddStockDate= {
        path => 'dueToStockDate',
        Value => $EXPDATE };

    $ORDQTY="20";
    my $AddOrderQty= {
        path => 'releaseQuantity',
        Value => $ORDQTY };

    $RELEASE="RELEASEID";
    my $AddReleaseId= {
        path => 'userFieldAmount1',
        Value => $RELEASE };

    $PARTNBR="PART";
    my $AddPartNum= {
        path => 'item',
        Value => $PARTNBR };

    $AddXML->{'System-Link'}{Request}{Create}{DomainEntity}{Key}{Property}[0] = $AddOrder;
    $AddXML->{'System-Link'}{Request}{Create}{DomainEntity}{Key}{Property}[1] = $AddLine;
    $AddXML->{'System-Link'}{Request}{Create}{DomainEntity}{Property}[0] = $AddStockDate;
    $AddXML->{'System-Link'}{Request}{Create}{DomainEntity}{Property}[1] = $AddOrderQty;
    $AddXML->{'System-Link'}{Request}{Create}{DomainEntity}{Property}[2] = $AddReleaseId;
    $AddXML->{'System-Link'}{Request}{Create}{DomainEntity}{Property}[3] = $AddPartNum;         
    $AddXML->{'System-Link'}{Logout}{sessionHandle} = $SessionHandle;

    $AddXML->apply_dtd($dtdContent);

    # Turn off output of DTD and meta tag generation
    my $xmldata = $AddXML->data(nometagen => 1, nodtd => 1);
    $xmldata =~ s/\?>/?>\n<!DOCTYPE System-Link SYSTEM 'SystemLinkRequest.dtd'>/m;

    print LOGF "{DEBUG} [" . localtime(time) . "] \tBuilding CREATE XML Request COMPLETED\n";
    print LOGF "{DEBUG} [" . localtime(time) . "] \tWriting CREATE XML Request to Request_$xml_filename STARTED\n";

    my $xml_filename = $RELEASE . "-" . time . ".xml";
    open $RequestLogfile, '>>', "$logsDir/XML/Release/Request_$xml_filename";
    print $RequestLogfile "\n--------------- CREATE REQUEST ---------------\n";
    print $RequestLogfile $xmldata;
    close $RequestLogfile;

Теперь вывод XML из приведенного выше кода:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE System-Link SYSTEM 'SystemLinkRequest.dtd'>
<System-Link>
  <Request broker="EJB" maxIdle="900000">
    <Create ApplyTemplate="(none)" domainClass="com.mapics.pm.PoItemRelease" name="createObject_PurchaseOrderItemRelease">
      <DomainEntity>
        <Key>
          <Property path="order">
            <Value/>
          </Property>
          <Property path="line">
            <Value/>
          </Property>
        </Key>
        <Property Value="20181207" path="dueToStockDate"/>
        <Property Value="4" path="releaseQuantity"/>
        <Property Value="9150021" path="userFieldAmount1"/>
        <Property Value="04-13165-02" path="item"/>
      </DomainEntity>
    </Create>
    <sessionHandle/>
    <workHandle/>
  </Request>
  <Logout>
    <sessionHandle/>
  </Logout>
</System-Link>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...