Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Madbit's XML Plugin - More Questions

Author
Message
freight hopper
22
Years of Service
User Offline
Joined: 26th Dec 2003
Location: Just beyond the Dunsmuir yard limits
Posted: 28th Mar 2012 18:29
Posting here because his Program Announcements entry is now locked.

Hi Madbit. Want to start using your plugin on some large, real-world xml files but

have a few questions and problems.


The first is that when I run the example code provided for the XML GET NEXT ELEMENT

command,




I get an unexpected result. It reports 5 children. I would expect 3 (see attached graphic on this entry and another on the following)

freight hopper
22
Years of Service
User Offline
Joined: 26th Dec 2003
Location: Just beyond the Dunsmuir yard limits
Posted: 28th Mar 2012 18:32
Attached is a graphic of the "tree". Looks like 3 children to me.

MadBit
VIP Member
Gold Codemaster
17
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 28th Mar 2012 21:15
Hi,
so far everything is correct. Each comment-node and text-node is also a child. So 5 Children are shown (3 elements, 1 comment and 1 text).

With Computers you can solve Problems that you have never befor.
Share your knowledge. It's a way to achieve immortality. (Tenzin Gyatso)
freight hopper
22
Years of Service
User Offline
Joined: 26th Dec 2003
Location: Just beyond the Dunsmuir yard limits
Posted: 28th Mar 2012 22:09
OK, thanks for the clarification.

Another question. In the example below, I want the 5th element and can get its name and text just fine.




In the following example, which has "mixed content" (sub-elements and text), I can't seem to get the text.



I don't see "African" like I would expect.

MadBit
VIP Member
Gold Codemaster
17
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 29th Mar 2012 10:50
Put your text-node as the first node of all your other children in your parent-element. Than it works.

XML GET TEXT -> get the first child. If this child a text-node than return the text in it. Otherwise it return a clear string.

Here the corrected xml file.


With Computers you can solve Problems that you have never befor.
Share your knowledge. It's a way to achieve immortality. (Tenzin Gyatso)
freight hopper
22
Years of Service
User Offline
Joined: 26th Dec 2003
Location: Just beyond the Dunsmuir yard limits
Posted: 29th Mar 2012 18:53
Good to know. Actually, I was imitating the order I saw in the XML GET NEXT ELEMENT example code, which has the text below the sub-elements. I am an XML noob. Hopefully, the real-world files I'm working with will all have text above sub-elements in any mixed content. If not, it could get messy. Not trying to be critical. If not already there, your plugin is approaching awesome.


Need to know a bit more about the XML RELEASE ELEMENT command, since I will be processing very large files and want to avoid a million memory leaks.

Q1. Since the same "ToElement" number can be "re-used" for successive operations, is releasing that same element number one time at the end sufficient?

Q2. It seems that if I release an element number that has already been released, it fails silently (good thing). It also seems that if I release an element number that has never been used, it fails silently (good thing). Put another way, in the absence of a "release all" command, do you see any problems with the following code?




XML GET NEXT ELEMENT. This has two forms. I will have a need to parse an unknown number of the same element name. There could be ten or ten thousand of them. With the following code I can get the text of the first instance of "JUNGLE" and all successive "JUNGLE"s.




The second form of the command seems applicable but will always error out after the last one is reached.



Q3. Is there any way to intercept the error? Maybe an option to turn it off?

MadBit
VIP Member
Gold Codemaster
17
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 29th Mar 2012 21:29
Q1: YES

Q2: Listing 1: It is a better way to check of valid xml node before you release an element. but your code works fine, too.


Q2: Listing 3: mmh, try this code. remains the error? What error message. I have no one implemented.



Listing2: This code have a problem with mixed locations.
example:
a xml-file with elements
JUNGLE
JUNGLE
DESSERT
JUNGLE

you can only access the first two jungles the last one will never reached. Better use Listing 3 or better my version of listing 3.

With Computers you can solve Problems that you have never befor.
Share your knowledge. It's a way to achieve immortality. (Tenzin Gyatso)
freight hopper
22
Years of Service
User Offline
Joined: 26th Dec 2003
Location: Just beyond the Dunsmuir yard limits
Posted: 30th Mar 2012 01:07 Edited at: 30th Mar 2012 01:13
Thanks, for the corrections. The following code is admitedly lame, but at least it will generate the error message (at least the __ invalid element id __ part).




I have attached a jpg of the message to this entry. Thanks for listing 3. I now get XML IS VALID ELEMENT.

The files I'll be working with don't seem to have any mixed locations. If they do, I can always inspect each element. Thank you, this has been most helpful.

freight hopper
22
Years of Service
User Offline
Joined: 26th Dec 2003
Location: Just beyond the Dunsmuir yard limits
Posted: 30th Mar 2012 02:15
Here is example code that enables one to concentrate on a particular element name.



MadBit
VIP Member
Gold Codemaster
17
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 30th Mar 2012 09:58
Quote: " The following code is admitedly lame, but at least it will generate the error message (at least the __ invalid element id __ part)."


Now I understand what you mean. That's less than an error message. That indicates the retrieved element-id is invalid. Your and my loop go throug the elements as long as the id is valid. Then when you retrieve the text of this element-id, you get the text shown above. The solution is, fill the id with a valid element. Or before you query this id, do you check the validity of it.

At first i thought the messagebox would be mine.

With Computers you can solve Problems that you have never befor.
Share your knowledge. It's a way to achieve immortality. (Tenzin Gyatso)

Login to post a reply

Server time is: 2026-07-09 15:47:26
Your offset time is: 2026-07-09 15:47:26