Tell if all xml elements are empty

E

Eric Goforth

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
 
C

Cor Ligthert

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
 
E

Eric Goforth

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
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top