Baanboard.com

Go Back   Baanboard.com > Forum > Baan Quick Support: Functional & Technical > Tools Development

User login

Frontpage Sponsor

Main

Poll
As a Customer What would do to keep your ERP Implementation intact
Proactively define Business Process-- Take the Project Ownership
50%
Handover everything to System Integrator from drawing BP till implementation of ERP
13%
Hire more inhouse skilled & capable IT Resource to work directly with SI
38%
Rely on SI Architects/Consultants
0%
Total votes: 8

Baanboard at LinkedIn


Reference Content

Reply
 
Thread Tools Display Modes
  #1  
Old 15th October 2020, 19:42
avpatil avpatil is offline
Guru
 
Join Date: Feb 2002
Posts: 777
avpatil is on a distinguished road
Baan: IVc3 - DB: SQL2000 - OS: Win 2003
XML generation
Baan: Other/Unknown
C/S: None/Unknown

Hi,
I am getting error while generating XML . I used the example given in this forum . The link is posed below.

http://www.baanboard.com/programmers...xml_generation

I am generating XML file on local directory (not on server). The return value of xmlWritePretty is -1 . Are there any includes I need to include.

Regards

Arvind Patil
Reply With Quote
  #2  
Old 16th October 2020, 09:40
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,491
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
Can you post your code?
How are you opening the file for writing on local?
If you are opening the file, what is the return value you are getting?
Is the file being created for writing?

If you don't have any compilation issues, you are good and you don't need any additional includes.
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!
Reply With Quote
  #3  
Old 16th October 2020, 10:11
avpatil avpatil is offline
Guru
 
Join Date: Feb 2002
Posts: 777
avpatil is on a distinguished road
Baan: IVc3 - DB: SQL2000 - OS: Win 2003
XML error

Hi,
Here is the code.
The file does get created in local directory but with 0KB.
The return value of seq.open.local() is positive
The return value of xmlWritePretry is -1.


function test.xml(
domain tcmcs.str300m i.file.name)
{
long cmfId, identId, recipientsId, fromId, dtdId
long fd, retVal
|Create the doctype element and populate its contents
dtdId = xmlNewNode("CMF", XML_DTD)
retVal = xmlsetAttribute(dtdId, "NAMEURL", "cmf1.dtd")

|Create the root element and make it a right sibling of the XML_DTD node.
cmfId = xmlNewNode("CMF" )
retVal = xmlAdd(dtdId, cmfId )

|Create IDENTIFICATION element and add its attributes
identId = xmlNewNode("IDENTIFICATION", XML_ELEMENT, cmfId)

retVal = xmlSetAttribute (identId, "MESSAGE-ID", "34a98u0erirori" )
retVal = xmlSetAttribute(identId, "CLASS", "order" )
retVal = xmlSetAttribute(identId, "SUBJECT", "Subject string" )

|Create RECIPIENTS element
recipientsId = xmlNewNode("RECIPIENTS", XML_ELEMENT, cmfId)

|Create FROM element and add its attributes
fromId = xmlNewNode("FROM", XML_ELEMENT, recipientsId)

retVal = xmlSetAttribute(fromId, "NAME", "Wiebe Riphagen" )
retVal = xmlSetAttribute(fromId, "TYPE", "SMTP" )
retVal = xmlSetAttribute(fromId, "ADDRESS", "wriphagen@baan.nl" )

|Open a file for write and store the XML document
fd = seq.open.local(i.file.name, "w" )
retval = xmlWritePretty(fd, dtdId, 0 )
seq.close(fd)

|Free the complete XML object from memory
xmlDelete(dtdId, 0)
}
Reply With Quote
  #4  
Old 16th October 2020, 10:52
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,491
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
So, looks like there were some issues with your code and with the code in the document.

1. You need to use "wt" for writing in text mode. (for prettifying the content)
2. You need to use seq.close.local() for closing the file.
2. writePretty will not work with local file (seq.open(), pipe.open(), ims.openfba() or ims.openvba() refer Prog Manual) so, you will need to use writePrettyToString and then write that string to your file
3. The document code had xmlAdd which is not right. It should refer parent node while using xmlNewNode for creating<CMF> element.

I've fixed them. Try this code -

Code:
	long cmfId, identId, recipientsId, fromId, dtdId
	long fd, retVal
	|Create the doctype element and populate its contents
	dtdId = xmlNewNode("CMF", XML_DTD)
	retVal = xmlsetAttribute(dtdId, "NAMEURL", "cmf1.dtd")

	|Create the root element and make it a right sibling of the XML_DTD node.
        | cmfId = xmlNewNode("CMF" )              |#BC.so //Invalid Code
        | retVal = xmlAdd(dtdId, cmfId )          |#BC.eo

	cmfId = xmlNewNode("CMF",XML_ELEMENT,dtdId)  |#BC.n //Correct way to create an element

	|Create IDENTIFICATION element and add its attributes
	identId = xmlNewNode("IDENTIFICATION", XML_ELEMENT, cmfId)

	retVal = xmlSetAttribute (identId, "MESSAGE-ID", "34a98u0erirori" )
	retVal = xmlSetAttribute(identId, "CLASS", "order" )
	retVal = xmlSetAttribute(identId, "SUBJECT", "Subject string" )

	|Create RECIPIENTS element
	recipientsId = xmlNewNode("RECIPIENTS", XML_ELEMENT, cmfId)

	|Create FROM element and add its attributes
	fromId = xmlNewNode("FROM", XML_ELEMENT, recipientsId)

	retVal = xmlSetAttribute(fromId, "NAME", "Wiebe Riphagen" )
	retVal = xmlSetAttribute(fromId, "TYPE", "SMTP" )
	retVal = xmlSetAttribute(fromId, "ADDRESS", "wriphagen@baan.nl" )

	|Open a file for write and store the XML document
        string buffer(3000)     |#BC.sn
	fd = seq.open.local(i.file.name, "wt" )
	retval = xmlWritePrettyToString(buffer,dtdId)
        seq.write.local(buffer, 3000,fd)
	seq.close.local(fd)     |#BC.en

	|Free the complete XML object from memory
	 xmlDelete(dtdId, 0)
}
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!
Reply With Quote
Sponsored Links
  #5  
Old 16th October 2020, 11:04
avpatil avpatil is offline
Guru
 
Join Date: Feb 2002
Posts: 777
avpatil is on a distinguished road
Baan: IVc3 - DB: SQL2000 - OS: Win 2003
Thanks Bhushan. I will try this.

Regards

Arvind
Reply With Quote
  #6  
Old 16th October 2020, 11:12
avpatil avpatil is offline
Guru
 
Join Date: Feb 2002
Posts: 777
avpatil is on a distinguished road
Baan: IVc3 - DB: SQL2000 - OS: Win 2003
Hi Bhushan,
Now I get the file but file contains omy

<?xml version="1.0"?>
<!DOCTYPE CMF SYSTEM "cmf1.dtd">

Regards
Arvind
Reply With Quote
  #7  
Old 16th October 2020, 11:18
avpatil avpatil is offline
Guru
 
Join Date: Feb 2002
Posts: 777
avpatil is on a distinguished road
Baan: IVc3 - DB: SQL2000 - OS: Win 2003
Hi Bhushan,
It is working now. I missed your other change. Thanks for the help

Regards

Arvind
Reply With Quote
  #8  
Old 16th October 2020, 11:19
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,491
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
Awesome! Glad it worked.
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!
Reply With Quote
  #9  
Old 16th October 2020, 14:29
avpatil avpatil is offline
Guru
 
Join Date: Feb 2002
Posts: 777
avpatil is on a distinguished road
Baan: IVc3 - DB: SQL2000 - OS: Win 2003
XML error

Hi,
I am getting attached error. Here is the XML

<?xml version="1.0"?>
<!DOCTYPE CMF SYSTEM "cmf1.dtd" [

<CMF>

<IDENTIFICATION
MESSAGE-ID="34a98u0erirori"
CLASS="order"
SUBJECT="Subject string"
/>
<RECIPIENTS>
<FROM
NAME="Wiebe Riphagen"
TYPE="SMTP"
ADDRESS="wriphagen@baan.nl"
/>
</RECIPIENTS>
</CMF>

]>
Attached Files
File Type: pdf error.pdf (27.9 KB, 2 views)
Reply With Quote
  #10  
Old 16th October 2020, 16:20
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,491
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
Try this -

Code:
|Create the doctype element and populate its contents
   dtdId = xmlNewNode("CMF", XML_DTD)
   retVal = xmlsetAttribute(dtdId,  "NAMEURL", "cmf1.dtd")

   |Create the root element and make it a right sibling of the XML_DTD node.
   cmfId = xmlNewNode("CMF" )
   retVal = xmlAdd(dtdId, cmfId )

   |Create IDENTIFICATION element and add its attributes
   identId = xmlNewNode("IDENTIFICATION", XML_ELEMENT, cmfId)

   retVal = xmlSetAttribute (identId,  "MESSAGE-ID", "34a98u0erirori" )
   retVal = xmlSetAttribute(identId,   "CLASS", "order" )
   retVal = xmlSetAttribute(identId,   "SUBJECT", "Subject string" )

   |Create RECIPIENTS element
   recipientsId = xmlNewNode("RECIPIENTS", XML_ELEMENT, cmfId)

   |Create FROM element and add its attributes
   fromId = xmlNewNode("FROM", XML_ELEMENT, recipientsId)

   retVal = xmlSetAttribute(fromId,  "NAME", "Jan Jansen" )
   retVal = xmlSetAttribute(fromId,  "TYPE", "SMTP" )
   retVal = xmlSetAttribute(fromId,  "ADDRESS", "jjansen@example.com" )





	|Open a file for write and store the XML document
   string buffer(3000)     |#BC.sn
	fd = seq.open.local(i.file.name, "wt" )
   retval = xmlWritePrettyToString(buffer,dtdId)
   seq.write.local(buffer,len(buffer),fd)
   retval = xmlWritePrettyToString(buffer,cmfId)
  |Remove the <?xml version="1.0"?> part
   buffer = buffer(23;len(buffer))
   seq.write.local(buffer,len(buffer),fd)
	seq.close.local(fd)     |#BC.en

	|Free the complete XML object from memory
	xmlDelete(dtdId, 0)
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!
Reply With Quote
  #11  
Old 16th October 2020, 17:19
avpatil avpatil is offline
Guru
 
Join Date: Feb 2002
Posts: 777
avpatil is on a distinguished road
Baan: IVc3 - DB: SQL2000 - OS: Win 2003
Hi Bhushan,
After this change I noticed the file has this line twide
<?xml version="1.0"?>
What I did was when writing to string buffer second time remove the first 22 charater

fd = seq.open.local(i.file.name, "wt" )
retval = xmlWritePrettyToString(buffer,dtdId)
seq.write.local(buffer, len(buffer),fd)
retval = xmlWritePrettyToString(buffer,cmfId)
l.len = len(strip$(buffer))
buffer = buffer(22;l.len)
seq.write.local(buffer,len(buffer),fd)
And this works? Is there a better way to do ?
Arvind
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Namespace support OmeLuuk Tools Development 5 12th January 2016 15:29
Generic solution for writing XML files from Baan en@frrom Tools Development 1 11th April 2011 11:53
Baan VS XML cvkartik AFS/DDC/OLE: Function servers 3 3rd February 2010 08:57
Problem with multiple XML documents.... BaaNovva Open World, Portal & Decision Manager 0 11th February 2008 13:12
XML READING ERROR (baan IV) mr_suleyman Tools Development 5 2nd February 2007 16:08


All times are GMT +2. The time now is 12:55.


©2001-2020 - Baanboard.com - Baanforums.com