JDE XML Parser API

neelam7

Member
I am using XRCS API to parse a inbound XML file in enterprise one 9.2. I have created a JCHAR *ElementName and JCHAR *ElementText variable to get XML element name and text.
But when I use XRCS_getElementName and XRCS_getElementText, I get only the first character of the tag or value. How to fix this?
 
Any help on why I am not able to see the full ElementName and ElementText in C business function when trying to parse an XML file?
 
You may need to post some of your code to know why. Keep in mind that most of those APIs allocate the buffer (that later has to be free'd) and return a pointer in one of the function args, so you are usually passing a pointer to a pointer for element name, text, etc. As in:

Code:
JCHAR *pszElmTxt = (JCHAR *)NULL;
...
if(XRCS_getElementText(hElm, &pszElmTxt) == XRCS_SUCCESS)
...
XRCS_freeString(pszElmTxt);
 
Thanks Brian.
Here's the Code


/*****************************************************************************

* Source File: b56propo

*

* Description: Parse XML for Proposal Source File

*

* History:

* Date Programmer SAR# - Description

* ---------- ---------- -------------------------------------------

* Author 5/30/2018 Unkno Unknown - Created

*

* Copyright (c) J.D. Edwards World Source Company, 1996

*

* This unpublished material is proprietary to J.D. Edwards World Source Company.

* All rights reserved. The methods and techniques described herein are

* considered trade secrets and/or confidential. Reproduction or

* distribution, in whole or in part, is forbidden except by express

* written permission of J.D. Edwards World Source Company.

****************************************************************************/

/**************************************************************************

* Notes:

*

**************************************************************************/

#include <b56propo.h>

/**************************************************************************

* Business Function: CopyProposalXMLFile

*

* Description: Copy Propsal XML file to Table

*

* Parameters:

* LPBHVRCOM lpBhvrCom Business Function Communications

* LPVOID lpVoid Void Parameter - DO NOT USE!

* LPDSD56PR lpDS Parameter Data Structure Pointer

*

*************************************************************************/

JDEBFRTN(ID) JDEBFWINAPI CopyProposalXMLFile(LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD56PROPOSA lpDS)

{

#ifdef SOA_ENABLED

/************************************************************************

* Variable declarations

************************************************************************/

/************************************************************************

* Variable declarations

************************************************************************/

FILE *fpInFile = (FILE*)NULL;

JCHAR szErrorMsg[201] = _J("\0");

XRCS_hParser hParser = NULL;

XRCS_hDocument hDoc = NULL;

XRCS_hElement hRootElement = NULL;

XRCS_Status eXRCSStatus = XRCS_SUCCESS;

XRCS_hElement *hCMElements = (XRCS_hElement)NULL;

XRCS_hElement *hAssignElements = (XRCS_hElement)NULL;

XRCS_hElement *hAssignRowElements = (XRCS_hElement)NULL;

ID idReturnValue = ER_SUCCESS;

unsigned int nNumOfCMNodes = 0;

unsigned int nCMNodeCounter = 0;

unsigned int nNumOfAssignNodes = 0;

unsigned int nAssignNodeCounter = 0;

unsigned int nNumOfAssignRowNodes = 0;

unsigned int nAssignRowNodeCounter = 0;

JCHAR *szElementText = (JCHAR*)NULL;

JCHAR *szElementName = (JCHAR*)NULL;

ID idJDBReturn = JDEDB_PASSED;

JCHAR *newXMLString = (JCHAR*)NULL;

unsigned int n_Ele = 0;

HUSER hUser = (HUSER)NULL;

/************************************************************************

* Declare structures

************************************************************************/

/************************************************************************

* Declare pointers

************************************************************************/

/************************************************************************

* Check for NULL pointers

************************************************************************/

if ((lpBhvrCom == (LPBHVRCOM)NULL) ||

(lpVoid == (LPVOID)NULL) ||

(lpDS == (LPDSD56PROPOSA)NULL))

{

jdeErrorSet(lpBhvrCom, lpVoid, (ID)0, _J("4363"), (LPVOID)NULL);

return ER_ERROR;

}

idJDBReturn = JDB_InitBhvr(lpBhvrCom, &hUser, (JCHAR *)NULL, JDEDB_COMMIT_AUTO);

if (idJDBReturn != JDEDB_PASSED)

{

JDB_FreeBhvr(hUser);

return ER_ERROR;

}

/************************************************************************

* Set pointers

************************************************************************/

/************************************************************************

* Main Processing

************************************************************************/

/* Open the File in Read only mode */

fpInFile = jdeFopen(lpDS->szFlatFilePath, _J("r"));

if (fpInFile != (FILE*)NULL)

{

eXRCSStatus = XRCS_initEngine();

if (eXRCSStatus == XRCS_SUCCESS)

{

eXRCSStatus = XRCS_getParser(&hParser);

if (hParser)

{

eXRCSStatus = XRCS_parseXMLFile(hParser, lpDS->szFlatFilePath, &hDoc);

if (hDoc)

{

/* Success Parsing, Begin Import */

XRCS_getDocumentElement(hDoc, &hRootElement);

eXRCSStatus = XRCS_serializeDocumentToXMLStringNoEncoding(hDoc, &newXMLString);

if (hRootElement)

{

XRCS_getElementChildren(hRootElement, &hCMElements, &nNumOfCMNodes);

XRCS_getElementsByTagName(hRootElement, _J("Option"), &hCMElements, &n_Ele);

XRCS_getElementName(hCMElements[0], &szElementName);

eXRCSStatus = XRCS_getElementText(hCMElements[0], &szElementText);

/*Loop though xml*/

while (nCMNodeCounter < nNumOfCMNodes)

{

XRCS_getElementName(hCMElements[nCMNodeCounter], &szElementName);

if (jdeStrcmp(szElementName, _J("Job")) == 0)

{

XRCS_getElementChildren(hCMElements[nCMNodeCounter], &hAssignElements, &nNumOfAssignNodes);

nAssignNodeCounter = 0;

while (nAssignNodeCounter < nNumOfAssignNodes)

{

XRCS_getElementName(hAssignElements[nAssignNodeCounter], &szElementName);

/* process AssignmentRow elements */

if (jdeStrcmp(szElementName, _J("Proposal")) == 0)

{

XRCS_getElementChildren(hAssignElements[nAssignNodeCounter], &hAssignRowElements, &nNumOfAssignRowNodes);

nAssignRowNodeCounter = 0;

while (nAssignRowNodeCounter < nNumOfAssignRowNodes)

{

XRCS_getElementName(hAssignRowElements[nAssignRowNodeCounter], &szElementName);

if (jdeStrcmp(szElementName, _J("Action")) == 0)

{ /* AssignmentIdGUID elements will be processed below, get the element text */

XRCS_getElementText(hAssignRowElements[nAssignRowNodeCounter], &szElementText);

}

nAssignRowNodeCounter++;

}

XRCS_freeElementArray(hAssignRowElements, nNumOfAssignRowNodes);

}

nAssignNodeCounter++;

}

XRCS_freeElementArray(hAssignElements, nNumOfAssignNodes);

XRCS_freeString(szElementName);

szElementName = (JCHAR *)NULL;

if (szElementText != (JCHAR *)NULL)

{

XRCS_freeString(szElementText);

szElementText = (JCHAR *)NULL;

}

}

nCMNodeCounter++;

}

XRCS_freeElementArray(hCMElements, nNumOfCMNodes);

XRCS_freeElement(hRootElement);

}

else

{

jdeSprintf(szErrorMsg, _J("XML, XRCS_getDocumentElementXML Failed for [%ls]"), lpDS->szFlatFilePath);

jdeWriteLog(_J("b56propo"), 0, szErrorMsg);

}

XRCS_freeDocument(hDoc);

}

else

{

jdeSprintf(szErrorMsg, _J("XML File Parser, XRCS_parseXMLFile Failed for [%ls]"), lpDS->szFlatFilePath);

jdeWriteLog(_J("b56propo"), 0, szErrorMsg);

}

XRCS_freeParser(hParser);

}

else

{

 

jdeSprintf(szErrorMsg, _J("XML File Parser, XRCS_getParser, Failed"));

jdeWriteLog(_J("b56propo"), 0, szErrorMsg);

}

XRCS_terminateEngine();

}

jdeFclose(fpInFile);

}

#else

jdeTraceSz(NULL, _J("b56propo - called but system does not have SOA_ENABLED defined."));

#endif

}

 
 
Not immediately sure of your exact problem. However, as an aside I don't think you need to call XRCS_serializeDocumentToXMLStringNoEncoding, or jdeFopen for that matter (unless you are simply doing it in order to determine if the file exists, if you are then you should probably close the file immediately after opening)... and it looks like you may be leaking memory. For every XRCS_[xxxxx] call that allocates memory like XRCS_getElementText you have to have a XRS_[xxx free] call (the correct free call will be documented in the header file where the API call is declared). So if you call XRCS_getElementText within a loop you need to have a free call in the same loop (and maybe you are - w/o indenting its a little hard to tell). If you copied from existing pristine source BSFN you have to be careful. I have seen several existing pristine BSFNs that also leak memory when parsing XML data so if you copy their "design pattern" be careful... they have bugs.

I assume you are just trying to get the parsing first and then will add logic to actually do something with the data so maybe you planned to put some of this stuff in later and are just trying to get the parsing to work first. I would start by removing the stuff you don't need like XRCS_serializeDocumentToXMLStringNoEncoding just to simplify things.
 
Back
Top