By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,065 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,065 IT Pros & Developers. It's quick & easy.

Tell if all xml elements are empty

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.