473,772 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Possible to force output format of empty elements?

I have built a small integration app using VS .NET 2003 that extracts
orderinformatio n from a 'webshop'. Extracting the orderinformatio n 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 PreserveWhitesp ace property of the XmlDocument.
I've also looked at XmlNodeType and the difference between WhiteSpacehandl ing
and Significat WhitespaceHandl ing. 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 6356
"Clark Spencer" <Cl**********@d iscussions.micr osoft.com> wrote in message news:2E******** *************** ***********@mic rosoft.com...
It seems my only two choice are to live with the fact that carridge return
linefeeds are inserted into empty elements OR turn PreserveWhiteSp ace 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.TextW riter 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 WriteFullEndEle ment( ).

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 WriteFullEndEle ment( ) 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 WriteFullEndEle ment() {
base.WriteEndEl ement();
}
}
- - -

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******** *****@TK2MSFTNG P09.phx.gbl...
public override void WriteFullEndEle ment() {
base.WriteEndEl ement();
}


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

public override void WriteEndElement ( ) {
base.WriteFullE ndElement( );
}
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******** *****@TK2MSFTNG P09.phx.gbl...
public override void WriteFullEndEle ment() {
base.WriteEndEl ement();
}


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

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

Nov 12 '05 #4

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

Similar topics

0
1483
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 with non-xml browsers (i.e. ALL browsers). Is there an option to output empty elements with an explicit end tag, as in <div></div> ? This is strictly equivalent to <div/>, from an XML point of view, except it actually works! Of course, if I can...
3
5177
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 within the html document. When the Finish button is clicked, I need to check for any empty input boxes before loading the next aspx page...but it could be no boxes or five boxes, etc.? I've included my html output...if you have any ideas,...
6
9636
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 person has completed it. The format should be "00". For example, if the person puts 1 then it should become 01 and if the person puts 12 in the field then it should stay like that. If the person puts 2004 then it should become 04, and if the...
3
1742
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 help browser 3) ascii where every line must start with a '%' character (octave
2
26710
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 empty elements in the XML. How to do that ? I don't understand why there is no simple option to specify the output format, or did I miss something ? regards andreas
0
1381
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: public enum xColors { Red = 1,
8
1909
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 you have a page that takes an id number as a query string and displays different things based on that id number. If you were able to loop through running the aspx pages with id=100, id=200,
4
1498
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
2023
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 i want to read this and output as it looks but iam getting abnormal
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.