• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

xmlParse errror - Premature end of file

New Here ,
Jan 28, 2014 Jan 28, 2014

Copy link to clipboard

Copied

I have a file that queries orders and writes them out in xml to be polled by some software that reads the order into an erp system. It reads fine but I can't parse an xml reponse that will update order status with xmlParse , it throws an error. I get the software response xml with GetHTTPRequestData().content fine. I just can't do anything with it there. As soon as I add xmlParse it errors out.

I can write out the response to a seperate file and work on it there , but it get's overriden on the next iteration.I'm looking for an alternate solution. Is there any way to create some code to "catch" the xml in the seperate file I write or post it to ,  but not have the the code that will update my status table overwritten each time the request is sent?

This is not a web service , just plain xml with http post 's.Tks.

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 28, 2014 Jan 28, 2014

Copy link to clipboard

Copied

You can put a try/catch block around the xmlparse and then use an alternate parsing method is xmlparse fails -- maybe regular expression search. I guess the key is to determine why xmlparse is failing. Does it fail consistently, often, only under certain conditions? Maybe some code example might help as I'm somewhat confused about what you are doing and how.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 28, 2014 Jan 28, 2014

Copy link to clipboard

Copied

Hi Steve ,

I think it's an xmlParse bug because that 's where it breaks. Essentially , without too much detail. the flow goes something like this :

<cfset content type="text/xml">

<cfquery orders> <!--- queries all orders and order data with a certain status ---->

<!---  Some conditional to check if there are records

          if not , send a node with 0 for Number Of Orders

--->

<cfesle>

<!---  Loop through order data and create xml --->

<cfloop query=" orders" datasource="#config.dsn#">

<cfxml variable =  "myorders">

<!--- All the order data in xml nodes---->

</cfxml>

</cfloop>

<cfoutput>#myorders#</cfoutput>

<!--- Here's the issue--->

<cfset xmlPOST = GetHTTPRequestData().content>

<cfset xmlDOM = xmlParse(xmlPOST)> <!--- -breaks here--->

<!--- Do some work here to update status in tbl---->

<!--- Test response to make sure reader is sending it--->

<cffile action="write" output="#xmlPOST#" file="ExpandPath('status.cfm')">

However , I can grab #xmlPOST# and write it out to a file and get good xml back , so I know the software is sending xml , but it might be tripping up the xmlParse method. Here are is the xml I get back from the software that I write out to a seperate file and it's good , I should be updating table with a status of F and reason read failed :

<?xml version="1.0" encoding="utf-8"?>

<SetOrderStatus>

<WebOrderNumber>322571</WebOrderNumber>

<DocumentNumber>322571</DocumentNumber>

<Status>F</Status>

<Reason>Item number: APALI22 not found in ICITEM table for customer: BLO02A</Reason>

</SetOrderStatus>

So , I am getting the response back from the order reader I just can't work on it from the xml file I create to read from , and unfortunately that's the file the reader sends the post back to.  I hope I didn't confuse you further , thanks for your input!

Steve

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 28, 2014 Jan 28, 2014

Copy link to clipboard

Copied

I'm not sure where or why the GetHTTPRequestData() layer? Are you sending the request from the prior code to another server via an xml POST?

If this layer is required and you are sending it via a POST, then my guess is a character coding/encoding/decoding issue of some sort. I use xmlParse all the time without issue with CF9 and above so I have my doubts it is an xmlparse bug -- earlier CF versions maybe, but not CF9 or 10.

The xml you posted above looks correct. Can you cut & paste that into a string and run it through xmlparse? I'm not sure where to point you other than closly look at encoding issues.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 28, 2014 Jan 28, 2014

Copy link to clipboard

Copied

LATEST

Thanks Steve , I have to grab the response sent after the reader finishes reading my file , even if the read fails , like in the xml data above.

  It polls the file first , if there is an order it reads it in and then sends back a reponse. It sends that response back to the file it is reading.

So after the order xml data ends in my code , next I am trying to grab the readers reponse back to the file,  via GetHTTPRequestData().

If there is another method available I would be happy to see it. I am thinking you are right though , it could be an enoding issue and I am on CF7 ... Thanks for your feedback!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation