473,320 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Tell if all xml elements are empty

Hello,
If I do a:

dim mystr = "<myxml><element1 /><element2 /><element3 /><element4
/></myxml>"
dim xmldoc as new xml.document()
xmldoc.loaddoc(mystr)

What's the best way to tell if all of the elements in myxml are empty
(as they are in this case?

-Eric
Nov 21 '05 #1
3 1243
Eric,

I think that I would do it by looping through the String char by char, set a
switch when the char is ">" and than see if the next char is "<" when not I
would probably set a switch and exit the loop.

(probably I would not use a switch however to tell you).
\\\something like this not tested typed here, Dim CharOpen as Boolean
For i As Integer = 0 To myStr.Length - 1
If CharOpen = True
If myStr.Char(i) <> "<"c Then
'Is not empty
end if
If myStr.Chars(i) = ">"c Then
CharOpen = True
Else
CharOpen = False
end if
Next
////
It can as well with a for each mychar as char in mystr

I hope this helps?

Cor
Nov 21 '05 #2
Cor,

What I wound up doing:

Len(lXMLDoc.SelectSingleNode("myxml/element1").InnerXml) > 0

This doesn't check to see if any of the other elements are empty, but
in the case that I'm trying to trap for if element1 is empty, the
other elements are empty as well.

It seems like there would be some built-in property that would let me
do this.

-Eric

"Cor Ligthert" <no**********@planet.nl> wrote in message news:<uY**************@TK2MSFTNGP11.phx.gbl>...
Eric,

I think that I would do it by looping through the String char by char, set a
switch when the char is ">" and than see if the next char is "<" when not I
would probably set a switch and exit the loop.

(probably I would not use a switch however to tell you).
\\\something like this not tested typed here, Dim CharOpen as Boolean
For i As Integer = 0 To myStr.Length - 1
If CharOpen = True
If myStr.Char(i) <> "<"c Then
'Is not empty
end if
If myStr.Chars(i) = ">"c Then
CharOpen = True
Else
CharOpen = False
end if
Next
////
It can as well with a for each mychar as char in mystr

I hope this helps?

Cor

Nov 21 '05 #3
Eric,

You can use the XMLreader, however I think you will not be more happy with
the code you have to make for that.

Cor
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
3
by: Clark Spencer | last post by:
I have built a small integration app using VS .NET 2003 that extracts orderinformation from a 'webshop'. Extracting the orderinformation works fine. Appending the order elements in the...
3
by: laredotornado | last post by:
Hi, Wondered if there was a good one-liner for what I want to do in PHP 4. I have an array, with an arbitrary number of elements. I'd like to know if all the elements in the array are empty. ...
5
by: nuffnough | last post by:
This is python 2.4.3 on WinXP under PythonWin. I have a config file with many blank lines and many other lines that I don't need. read the file in, splitlines to make a list, then run a loop...
1
by: DrDavey | last post by:
What are the advantages/disadvantages of using a choice of a several "sub-"elements with empty content (and no attributes) vs. simple content. Here's an example: Using simple content:...
3
by: August Karlstrom | last post by:
Hi everyone, In XHTML, can any empty element <foo></foobe replaced by <foo />? Example: <table> <tr><td>1</td><td>2</td></tr> <tr><td /><td>4</td></tr> </table>
4
by: j_depp_99 | last post by:
Thanks to those guys who helped me out yesterday. I have one more problem; my print function for the queue program doesnt work and goes into an endless loop. Also I am unable to calculate the...
36
by: laredotornado | last post by:
Hi, I'm using PHP 5. I have an array of strings. What is the simplest way to remove the elements that are empty, i.e. where the expression "empty($elt)" returns true? Thanks, - Dave
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.