Groups | Blog | Home
all groups > dotnet xml > march 2005 >

dotnet xml : Ignorable Whitespace


Carlitos
3/7/2005 10:51:03 AM
Hi there,

A class in Xerces J-API (Java) called TextImpl contains a property that
returns whether the text is ignorable whitespace
(http://xml.apache.org/xerces-j/apiDocs/org/apache/xerces/dom/TextImpl.html#isIgnorableWhitespace()). ;

I guess when they refer to "ignorable whitespace" in Java we may interpret
that as an "insignificant whitespace" in .NET. Am I correct to say that?

So, I need to manually convert some Java code to C#, and the following
excerpt shows the converted code, except for the line marked with
"//<--****". I have spent a lot of time trying to find out how that
if-statement could be converted to C# with no success, mostly because I am a
beginner in XML.

The excerpt of code is this:

XmlNodeList children = node.ChildNodes;
string svalue;
if ( children != null )
{
//we want to delete ignorable whitespace from
//the dom tree
for ( int z = 0; z < children.Count; z++ )
{
if ( children.Item(z) is XmlText) // instanceof TextImpl )
{
svalue = children.Item(z).Value.Trim();

if ( (children.Item(z)).isIgnorableWhitespace() ) // <--****
{
node.RemoveChild( children.Item(z) );
z--;
}
}
}
}

Three questions:
1. Can we say that XmlText is the counterpart of Java Xerces' TextImpl
(reference:
http://xml.apache.org/xerces-j/apiDocs/org/apache/xerces/dom/TextImpl.html) ?

2. Is it correct and safe to say that the term "insignificant whitespace"
referred in MSDN Library is the same as saying "ignorable whitespace" in Java?

3. How would the code line marked with "//<--****" in above's excerpt be
coded in C#?

Many thanks in advance.

--
Carlitos
3/8/2005 4:49:04 AM
Many many mmmmmmany thanks, Oleg.

C


[quoted text, click to view]
Oleg Tkachenko [MVP]
3/8/2005 12:17:48 PM
[quoted text, click to view]

Yes, that's correct.

[quoted text, click to view]

Yes, it's safe.

[quoted text, click to view]

I believe it would be
if ( children.Item(z)).NodeType == XmlNodeType.Whitespace )

--
Oleg Tkachenko [XML MVP, MCP]
AddThis Social Bookmark Button