Baanboard.com

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

User login

Frontpage Sponsor

Main

Poll
For ERP LN feature pack upgrade, what method of install are you using?
Installation Wizard into existing VRC
35%
Installation Wizard into new VRC
42%
Manual into existing VRC
3%
Manual into new VRC
19%
Total votes: 31

Baanboard at LinkedIn


Reference Content

Reply
 
Thread Tools Display Modes
  #1  
Old 6th November 2006, 20:49
Trisli Trisli is offline
Unconfirmed User
 
Join Date: Nov 2004
Location: Denmark
Posts: 10
Trisli is on a distinguished road
Baan: IV and V - ERP LN being installed - DB: * - OS: *
XML parsing using "xmlFindSetOfSiblingNodes"
Baan: Other/Unknown
C/S: Both

Hi All,

I would like to read an XML file. At the third level of nodes there may appear different types of nodes in a random sequence. Example:


<Document>
<Chapter>
<Text>
...
...
</Text>
<Graphics>
...
...
</Graphics>
<Text>
...
...
</Text>
<Graphics>
...
...
</Graphics>
<Text>
...
...
</Text>
</Chapter>
</Document>

As you can see the "Text" node appears 3 times and "Graphics" 2 times, and they are mixed randomly. Each of the types must be handled in its own way (...different code). My question is now: How is the structure read?



Normally I would issue an "xmlFindFirst", and then loop using "xmlGetRightSibling" until the end of the structure. Each value of the structure is then read using "xmlGetDataElement". This method works fine when browsing through a list of nodes with the same structure, but in my example I need to process certain sub-nodes before others. And then I run into problems...

I have tried to use "xmlFindSetOfSiblingNodes". When executing it, it correctly results in a list of the nodes of the specified types. The question is now how to I process the resulting "enumeration" list into nodes that I can decompose.

What I cannot figure out is how to read the data of the individual nodes. The "xmlFindSetOfSiblingNodes" results in a "enumerate list" like:
<Enumeration TYPE="InMemory XmlNodes">
<e0>id0</e0>
<e1>id1</e1>
...
<en>idn</en>
</Enumeration>

The id0, id1, ... then point at the nodes, that I must process

Can someone help me?

Thanks in advance!
Reply With Quote
  #2  
Old 8th November 2006, 23:39
vahdani's Avatar
vahdani vahdani is offline
Guru
 
Join Date: Aug 2002
Location: Cologne, Germany
Posts: 418
vahdani is on a distinguished road
Baan: all - DB: all - OS: Unix / Win2K
Hi Trisli,

how about this for a fine piece of code?

Code:
function main()
{
        long	input_file_id
        long	xml_id
        long	texts_enum, enum_node, textnode
        String	text_data(100)
        String	error_string(100)

        |Open the XML file for reading.
        input_file_id = seq.open ("document.xml", "r" )

        |Parse the XML file
        xml_id = xmlRead(input_file_id, error_string)
        seq.close(input_file_id)

	if xml_id then
		texts_enum = xmlFindNodes(xml_id, "Text", 0)
	endif

	if texts_enum then
		enum_node = xmlFindFirstMatch("fChild", texts_enum)
		while enum_node
			|get text data
			textnode = lval(xmlData$(enum_node))
			text_data = xmlData$(textnode) 
			|get next node
			enum_node = xmlGetRightSibling(enum_node)
		endwhile
		|Free up memory
		xmlDelete(texts_enum)
	endif
}
__________________
May the force be with you!
Reply With Quote
  #3  
Old 13th November 2006, 08:47
Trisli Trisli is offline
Unconfirmed User
 
Join Date: Nov 2004
Location: Denmark
Posts: 10
Trisli is on a distinguished road
Baan: IV and V - ERP LN being installed - DB: * - OS: *
I finally made it work...

Hi Vahdani,

Thanks for your proposal. Unfortutenately it does not quite help me.
My challenge is that - after locating the first node node - executing a xmlGetRightSibling may result in various different node types. I need to sort and process the nodes in a certain sequence.

xmlFindSetOfSiblingNodes seems to be a briliant way of determining sub-sets of data the way I need to do it. Unfortunately I found no documentation on how to process the sub-document created by this command. Following my post I made the code below. It seems to work according to my wishes:

BaanBoard - xmlFindSetOfSiblingNodes.txt
Reply With Quote
  #4  
Old 13th November 2006, 17:59
vahdani's Avatar
vahdani vahdani is offline
Guru
 
Join Date: Aug 2002
Location: Cologne, Germany
Posts: 418
vahdani is on a distinguished road
Baan: all - DB: all - OS: Unix / Win2K
Hi Trisli,

I'm glad you found a solution. I am not sure if you did carefully look at my proposed solution. Here I use xmlGetRightSibling to go through the enumeration and not through the original XML!
__________________
May the force be with you!
Reply With Quote
Sponsored Links
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
create XML file from BAAN IV jdboer Tools Development 2 7th July 2006 16:51
Baan xml functions gous99 Tools Development 0 9th June 2004 18:41
Baan reports in XML format... r_nagu Tools Development 1 10th March 2004 23:45
XML connector examples sant123 Tools Development 1 26th February 2004 06:16
Redirect Print to xml file prajesh Tools Administration & Installation 5 8th July 2002 15:56


All times are GMT +2. The time now is 09:39.


©2001-2017 - Baanboard.com - Baanforums.com