473,467 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XML and VB6

1 New Member
hello. please help me to read an XML file like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ROOT>
<PERSONS>
<PERSON NOM="IARU" PRENOM="IOANA" >
<CONTACT>
<TEL>
<TEL1>111111</TEL1>
<TEL2>222222</TEL2>
</TEL>

<EMAIL>
<EMAIL1>EMAIL1@E.COM</EMAIL1>
</EMAIL>

<FAX>
<FAX1>373474747</FAX1>
</FAX>

<ADRESSE>
<RUE>RUE1</RUE>
<NO>NO1</NO>
<VILLE>VILLE1</VILLE>
</ADRESSE>
</CONTACT>
</PERSON>

<PERSON NOM="PALL" PRENOM="EVA" >
<CONTACT>
<TEL>
<TEL1>333333</TEL1>
<TEL2>444444</TEL2>
</TEL>

<EMAIL>
<EMAIL1>ema@yahoo.com</EMAIL1>
</EMAIL>

<FAX>
<FAX1>373474747</FAX1>
</FAX>

<ADRESSE>
<RUE>rue2</RUE>
<NO>no2</NO>
<VILLE>ville2</VILLE>
</ADRESSE>
</CONTACT>
</PERSON>
</PERSONS>
</ROOT>
in VisualBasic6.0.
Sep 4 '07 #1
1 1273
Robbie
180 New Member
Hi, I made a module which allows you to extract the text which is between tags in an XML or HTML file.
Have a look, play around with it a bit, I think you'll find it's what you need.
To use it you'll need to load the XML file into a string, then give that string to this function.
Expand|Select|Wrap|Line Numbers
  1. Public Function XMLTagText(XMLFileText As String, TagToUse As String, NumberToGive As Long) As String
  2. 'XML tag text extraction module by Robbi-985
  3. 'XMLFileText    -   The entire text of the XML (or HTML) file
  4. 'TagToUse       -   Will return text within this tag
  5. 'NumberToGive   -   Gives back the text in this number'th occurence
  6. '                   of the tag (i.e. if you have:
  7. '<a>Apple</a>
  8. '<a>Banana</a>
  9. '<a>Orange</a>
  10. '                   if NumberToGive is 3 then it gives back Orange.
  11. '                   Must be > 0!
  12.  
  13.  
  14.     Dim TagStartPos As Long
  15.     TagStartPos = 0
  16.     Dim TagEndPos As Long
  17.  
  18.     Dim CurrentNumber As Long
  19.     CurrentNumber = 0
  20.  
  21.     While CurrentNumber < NumberToGive
  22.  
  23.         TagStartPos = InStr(TagStartPos + 1, XMLFileText, "<" + TagToUse + ">")
  24.         If TagStartPos < 1 Then
  25.         'There's no open tag with the text of TagToUse
  26.             'Just give back nothing
  27.             XMLTagText = ""
  28.             Exit Function
  29.         End If
  30.  
  31.         CurrentNumber = CurrentNumber + 1
  32.     Wend
  33.  
  34.     TagEndPos = InStr(TagStartPos, XMLFileText, "</" + TagToUse + ">")
  35.     If TagEndPos < 1 Then
  36.     'There's an error in the formatting of the XML or HTML text!
  37.         'Help out explaining why this funciton's going to give
  38.         'back blankness by saying that there IS a format error
  39.         MsgBox "There's an open tag for '" + TagToUse + "'" + _
  40.         ", but no close tag!", vbExclamation, _
  41.         "XML or HTML format error!"
  42.         '...Then give back nothing
  43.         XMLTagText = ""
  44.         Exit Function
  45.     End If
  46.  
  47.     'Now we have the positions of the first character of the
  48.     'start and end tags
  49.  
  50.     'Add on the length of the entire tag (including <>)
  51.     '(So that we're left with the position which the
  52.     'text within the tag starts at)
  53.     TagStartPos = TagStartPos + 2 + Len(TagToUse)
  54.     'Similar thing with the ending position
  55.     TagEndPos = TagEndPos - 1
  56.  
  57.  
  58.  
  59.  
  60.     XMLTagText = Mid(XMLFileText, TagStartPos, (TagEndPos - TagStartPos) + 1)
  61.  
  62.  
  63. End Function
  64.  
  65.  
Sep 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.