473,288 Members | 1,693 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,288 software developers and data experts.

Possible to force output format of empty elements?

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 XmlDocument was also done in a jiffy.
The final step is to save the document to disk and then ship it to another
system using ftp. The xml orderfile produced must fit a set specification of
the recieving system. That specification states that empty elements must be
formated in one line using a long format for empty elements.

It should look like this:
<address1></address1>

And not like this:
</address1>
Or this:

<address1>
</address1>

When I save the xml order document to disk all empty elements are formatted
with a carridge return (0x0D) and linefeed (0x0A). Is it possible to force
output format of empty elements somehow? I want the empty elements formated
like this <address1></address1> - without the carridge return and linefeed.

I've looked at and tried the PreserveWhitespace property of the XmlDocument.
I've also looked at XmlNodeType and the difference between WhiteSpacehandling
and Significat WhitespaceHandling. It has made me all confused.

I realize that there are probably resonable explanations for this complexity
but right now I'm just looking for a quick answer.

Any help would be very appreciated!

Thanks,

Clark Spencer
Nov 12 '05 #1
3 6326
"Clark Spencer" <Cl**********@discussions.microsoft.com> wrote in message news:2E**********************************@microsof t.com...
It seems my only two choice are to live with the fact that carridge return
linefeeds are inserted into empty elements OR turn PreserveWhiteSpace off?

The last option removes the indentation which makes the xmldocument readable
to humans. The first option is not a valid option since I send carridge
returns instead of nothing to the recieving system.

Why are the carridge return line feed inserted? Does'nt anyone know?
If you're using a System.IO.TextWriter to receive the ouput, then
try changing the TextWriter's NewLine property to "".

Create each of the underlying Stream, TextWriter, and XmlTextWriter
around that which you may be using separately, so you can set this
on the TextWriter instance before you hand it to the XmlTextWriter.

: : "Clark Spencer" wrote:
It should look like this:
<address1></address1>

And not like this:
</address1>
<address1 />

: : Or this:

<address1>
</address1>


This is usually caused because the producer of the XML (an XslTransform?)
is using WriteEndElement( ) -- which will emit an end tag in the shortened
form if the element has no child content -- instead of WriteFullEndElement( ).

A workaround for this behavior is to inject an XmlTextWriter wrapping the
TextWriter you're already using, and that this "filter" would be made
responsible for intercepting calls to WriteEndElement( ) and substituting
calls to WriteFullEndElement( ) instead.

Try this class,

- - - XmlTextWriterEE.cs (complete)
using System;
using System.IO;
using System.Xml;

/// <summary>
/// Wrapper that forces more compact empty element end
/// tags to be written as full end tags whenever possible.
/// </summary>
public class XmlTextWriterEE : XmlTextWriter
{
public XmlTextWriterEE( TextWriter sink) : base( sink) {;}
public override void WriteFullEndElement() {
base.WriteEndElement();
}
}
- - -

Wrap this around your TextWriter (that you disabled NewLine on?)
and see if that helps with prying open the end tags into their more
verborse form.
Derek Harmon
Nov 12 '05 #2
"Derek Harmon" <lo*******@msn.com> wrote in message news:OF*************@TK2MSFTNGP09.phx.gbl...
public override void WriteFullEndElement() {
base.WriteEndElement();
}


Actually, upon further review, this should've been, ;-)

public override void WriteEndElement( ) {
base.WriteFullEndElement( );
}
Derek Harmon
Nov 12 '05 #3
Thank you Derek!

I'll try this solution as soon as possible.

Sincerely,

Clark
-------------------------------------------------

"Derek Harmon" wrote:
"Derek Harmon" <lo*******@msn.com> wrote in message news:OF*************@TK2MSFTNGP09.phx.gbl...
public override void WriteFullEndElement() {
base.WriteEndElement();
}


Actually, upon further review, this should've been, ;-)

public override void WriteEndElement( ) {
base.WriteFullEndElement( );
}
Derek Harmon

Nov 12 '05 #4

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

Similar topics

0
by: yzzzzz | last post by:
Hi, I'm outputting XML to XHTML using xsltproc. There happens to be a few empty tags in the output (such as <div></div>) but xsltproc outputs them as <div/>. This causes compatibility problems...
3
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
6
by: WindAndWaves | last post by:
Hi Gurus In my quest in putting my first javascript together, I am now trying to conquer something that seems trivial, but has taken me hours. I would like to format a field in a form once the...
3
by: danmc91 | last post by:
Hi, I'm just getting going with xml and xslt. I'm trying to write what are essentially man pages and I need 3 output formats. 1) nroff -man format for real man pages 2) html for an online...
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...
0
by: Horia Tudosie | last post by:
Using Visual Studio 2003 This is to report a series of bugs regarding the FlagsAttribute and (independently) the usage of interfaces in Web applications. Let’s declare xColors type like: ...
8
by: Daniel | last post by:
Hi, Does anyone know if it is possible to put an aspx page inside of another? OR run an aspx page and capture the output as a string and then write this out to a page.... So for example say...
4
by: Lord0 | last post by:
Hi there, Is the following possible with XSLT? Given the following example XML docs: <!-- doc 1--> <user> <username>myUsername</username> <password></password> <phone>12345</phone>
9
by: srikanth | last post by:
i have a text file like below, test.txt file (actually my test file file is with 10000 lines but here i tested with 3 lines) 3 06.09.2006 16:37:25 3 06.09.2006 16:40:02 3 06.09.2006 16:42:31...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
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
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
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...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...

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.