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
0
Spencer (11)
8/30/2004 8:33:05 AM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
497 Views

Similar Articles

[PageSpeed] 49

"Clark Spencer" <ClarkSpencer@discussions.microsoft.com> wrote in message news:2E0EE598-377F-4103-A4E2-12D1FD29F867@microsoft.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


0
loresayer (274)
8/31/2004 4:26:48 AM
"Derek Harmon" <loresayer@msn.com> wrote in message news:OFkiqKxjEHA.712@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


0
loresayer (274)
8/31/2004 4:34:37 AM
Thank you Derek!

I'll try this solution as soon as possible.

Sincerely,

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

"Derek Harmon" wrote:

> "Derek Harmon" <loresayer@msn.com> wrote in message news:OFkiqKxjEHA.712@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
> 
> 
> 
0
8/31/2004 9:37:08 AM
Reply:

Similar Artilces:

Conditional formatting on book shared
Hi, I know when a book is shared, conditional formatting is unavailable but is there any way to get (or see) the conditions of this cell ? thanks in advance loparqu -- Message posted from http://www.ExcelForum.com Can you copy the cell and paste into a new workbook's worksheet and look at the CF there? "loparque <" wrote: > > Hi, > I know when a book is shared, conditional formatting is unavailable, > but is there any way to get (or see) the conditions of this cell ? > > thanks in advance > > loparque > > --- > Message posted from ...

File formats
I have a question concerning file formats. As a small business manager using personal computers in the workplace is essential. Over the course of any fiscal year documents are generated and files produced which are important for maintaining from year to year. Often these important files are generated in Microsoft Word and Excel in my work. I recently referred to one such file that was 5 years old to see the frightening words: “File Error: data may have been lost.” My question related to which file formats are best for file retention. I am not interested in paying a com...

Copy Paste Conditional Formatting
I have used conditional formatting to identify certian parameters. I must now copy that column to another spreadsheet but do not want to lose that highlighted data. I have tried Copy Paste Special but I can only copy the Values. Is there any way to copy those cells and the colors? If you do a copy/paste special/formats, you'll get the conditional formats (and other formats) into the destination cells, without changing the values already in those cells. -- Jim "Bud Hughes" <BudHughes@discussions.microsoft.com> wrote in message news:CAA3085A-642D-4645-ADC5-24FF967...

Is it possible
I would like to know is it possible to make million dollar in the internet, if you have any suggestions, write on my forumhttp://isitpossible.truemillion.comMark...

Personal Folders in OWA
Hello, I have just enabled OWA on our Exchange 2003 SP2 through ISA Server 2004. Is there any way to access personal folders in OWA? Thanks in advance. If by personal folders you mean .pst files, the answer is NO! Sorry. C C wrote: > Hello, > > I have just enabled OWA on our Exchange 2003 SP2 > through ISA Server 2004. Is there any way to > access personal folders in OWA? > > Thanks in advance. > > "C C" <someone@atsbcglobal.net> wrote: >I have just enabled OWA on our Exchange 2003 SP2 >through ISA Server 2004. Is there any way...

Format so first column always appears
I have a wide worksheet and want the first column to always appear as I scroll to the other columns. I would look it up but I can't figure out where to look and under what title. Thanks It's referred to as Freeze Panes. Position your cursor in B1 then click on View | Freeze Panes | Freeze Panes (Excel 2007 or later), or Window | Freeze Panes (Excel 2003 or earlier). Hope this helps. Pete On Aug 20, 1:26=A0am, Gianni <gia...@gianni.com> wrote: > I have a wide worksheet and want > the first column to always appear > as I scroll to the other columns. > > I would...

Downloading Statements Directly Not Possible
I have Money 2002 installed on an Win XP Pro SP1 machine. Something happened and I probably did it, that causes the statement downloads not to go directly to the account. Rather they want to be saved in a file and then opened into Money. I then have to delete the download. I have tried several things in order to fix this: 1. I verified the file associations of OFC, OFX were correct. They were. 2. Lowered all my security settings in IE. Even put banks into Trusted site zone. No go. 3. Made new accounts. Didn't help. 4. My IE cache is large (500MB) and regularly cleaned out. 5. I made s...

is this possible? reload a form that is based on a query with new query that is defined in the form.
I have a basic form. The form is based on a query, so when I open the form, a pop comes up where I enter in what I want to query. So instead of 30,0000 records, I get 1-10 records. on the form, I have a text box. I want to be able to enter in what I want to query next and afterupdate have the recordset/form reload with that query instead of my original qeury. I figure this has to be done with VB. I am just starting to learn some VB but I am lost. Any info would be great, thank you. It does. You need to apply the new query or table name, or the sql string to the forms recordsource, then...

Conditional Formatting
All: I have a sheet with conditional formatting applied, the conditions work but once I save and come back, when the specific conditional format is triggered, it looks like nothing happened. When you scroll up/down or switch between tabs and then come back, that's when the conditional formatting is visible. Working in Excel 2007 and it's important for users to see the formatting happening in view, and not having to scroll back and forth to see the changes. Any thoughts why this is happening? Thank you. ...

Address format
Is it possible to save email addresses in the format? "Firstname Surname" securemail@domain.com This is required for a gateway certificate server. Microsoft <peter@4dt.co.za> wrote: > Is it possible to save email addresses in the format? > > "Firstname Surname" securemail@domain.com > > This is required for a gateway certificate server. Save them where? -- Brian Tillman [MVP-Outlook] ...

Possible to detect changes to an XmlDocument object?
If I instantiate an XmlDocument object, the load a file through the Load method, is there a way, later on in execution, to easily determine if the XmlDocument object has changed from the original version loaded? I'd like to be able to check a condition to see if the document in memory has been editted (i.e., nodes added, attributes changed, etc.) so that my user can decide whether or not to commit changes to the disk file before moving to another file. Will I have to resort to re-loading the file, and comparing OuterXml properties? Gabe Gabe Covert wrote: > I'd like t...

I need an excel plug in to save workbooks in adobe acrobat format
I used to have this feature on the toolbar, but following a severe recent excel and outlook crash, it got wiped off !! There seems to be no way to restore this essential facility, of choosing to save excel workbooks in a pdf format instead of xls. DOes anyone know how to restore it? Hi Chris, Try-File, Print, then select Acrobat Distiller. It will then ask you where you want the .pdf file to be saved. Thats how it works on mine. Hope that helps "chris brown" wrote: > I used to have this feature on the toolbar, but following a severe recent > excel and outlook crash,...

Custom 0\.00 Format with Comma
I have a workbook where numbers are entered as whole numbers (includes cents but no decimal point) on one worksheet. These numbers are pulled into another worksheet and I need the numbers to have decimal points before the last two numbers. From another post, I found out I can do this by formatting these cells as Custom = 0\.00 . Is there a way to have the comma appear before the thousands? No. When you ask Excel to insert commas into a number, it will do so in groups of three before the decimal point. However, Excel thinks your decimal point is after the cent, not after ...

Is it possible to compare a string and a field name
I have the following tables: Membership, Subscriptions, OfficeUseOnly. The Office Table contains a Year, Year To and From [financial year] and the other fields are the 5 membership types (regular, student etc) and these 5 fields contain the different amount each type of member has to pay. I want to create a form whereby on entering the financial year and the membership type the correct amount is automatically inserted into the 'Amount' field: FinancialYear - in current form = OfficeUseOnly SubsFinYear and then if MemberType = 'Student' find Student field ...

pictures in various shapes
Is it possible to insert a picture and make it into a circle or an oval or various other shapes than just squares and rectangles? Thank you ahead of time. with a graphics editor -- Rob Giordano Microsoft MVP - FrontPage "Stephanie" <Stephanie@discussions.microsoft.com> wrote in message news:014D0D06-15F9-4D92-8D93-64FBD3A9CA32@microsoft.com... | Is it possible to insert a picture and make it into a circle or an oval or | various other shapes than just squares and rectangles? Thank you ahead of | time. | | Stephanie wrote: > Is it possible to insert a pict...

Excel 2002 SP3 CSV Format Cell 'Special' Leading Zero
Excel 2002 SP3, CSV File, Format Cell 'Special' for Zip Code Leading Zero does not work. Is there any way to maintain the Zip Code Leading Zero (New England States) in a CSV File? I have tried Format 'Special' and 'Text' and have found the only solution to be to place a leading ' with each zip code. This is not a very practical solution. Is this a configuration problem, a bug, or a limitation of the CSV file? Thanks, William Hi you may use an adjacent cell with a formula for this. e.g. enter in B1 =TEXT(A1,"0000") or something similar according...

conditional formatting #15
I have applied conditional formatting to a cell on a form that is printed on a black and white printer so the formatting is somewhat ruined as you cannot distinguish between the shades of grey. If I try and use =IF(J10>=3,"Critical","Ok") it of course returns a circular reference error as it is referring to itself. Is there a way to achive this perhaps in VBA so that I can apply the logical rules but return a text string. regards in advance Peter Instead of colours, you could use a pattern from the Pattern dropdown in the conditional formatting Patterns tab. ...

Is this possible
I want to make a list of the files in several different folders. Is it possible to somehow "Copy and paste" just the filenames into a list, in either Word or Excel or Wordperfect. I am just trying to sort the files in several different folders to weed out duplicates. There has got to be an easier way then typing them all or screen printing the lists and manually weeding them out. Any suggestions. Frustrated... Hans, Here is some code that will start in a directory and list all files in that and any sub directories. It uses recursion to go through all the subs. Just ch...

Formatting Question #6
I have a field in my spreadsheet that is typed in as 6/29/5. How can I change this to 6/29/2005? Select the cells, go to Format>Cells, click Date in the list of categories & pick what you want from the choices offered. You should find what you want there. HTH |:>) "Metalteck" wrote: > I have a field in my spreadsheet that is typed in as 6/29/5. How can I change > this to 6/29/2005? ...

Sent Items Appears empty but not.
Hello, I have a user that has Outlook 2000 in a CW setup with Exchange 2000 Server (do have mixed mode with 5.5 and ADC but the mailbox is on the 2000 server). Anyway they got rid of a ton of mail but the mailbox did not go down in size. I looked at thier desktop and if you right clicked the entire mailbox to veiw sizes of folders the sent items folder contained 141,598KB but showed nothing in it. I went to server and opened her sent items through the MBX folder and it contained a ton of stuff, over 3,400 items. I deleted it and it left and the size went down. But the problem is now...

Number Format (custom)
I want a custom type that will take '5W' and put a zero in front, making it '05W'. I used the 00 custom type and it would turn 5 into 05. I got a reply to an earlier post suggesting to use "0"@. This worked but I forgot to mention that if 05W or 15W was entered I want it left alone. "0"@ added the zero to the beginning turning it into 005W or 015W. No real way to build logic into a number format in excel. in a number format you tell it what you want a positive number to look like, a negative number, zero and text. "barryderay" wrote: ...

Is this Possible ?
Hi Have a newsletter document with text boxes that have no outlines but internal gradient colour fills. Is it possible that a macro could remove all colour fills in one hit just leaving the text in place ? many thanks Dim oShape As Shape For Each oShape In ActiveDocument.Shapes If oShape.Type = msoTextBox Then If oShape.Line.Visible = msoFalse Then oShape.Fill.Visible = msoFalse End If End If Next oShape should clear the fill from text boxes that are filled and have no border. -- <>>< ><<> ><&l...

Is Batch Marking Possible?
Hello, I am doing a mass mailing from Outlook. I will print 50 address labels per day. Is there a way for me to batch-mark the contacts for which I print a label? Thanks, Talal Itani ...

Opening Page format
Using MS Publisher 2002, I want the opening page to show only a blank page, not a graphic showing - in a third of the screen - a selection of "scheme - options - designs" Help/advice will be appreciated. If it takes up a third of the page you must be using 640 x 480 - UNBELIEVABLE Go to menu Tools > Options tab General second item down - DE-select -- On Wed, 10 Sep 2003 17:44:07 +1000, "���MS�Publisher���" <donotknock@nobodyhome.com> wrote: >If it takes up a third of the page you must be using 640 x 480 - >UNBELIEVABLE I'm not. > >Go to me...

Is it possible to make cmd window to flash?
Greetings, I have an existing VC2003 windows console program. Now I want to add a alarm feature to it, the simpliest way is to make the cmd window to flash. Can this be implemented? Thanks, Evan >I have an existing VC2003 windows console program. Now I want to add a alarm >feature to it, the simpliest way is to make the cmd window to flash. Can >this be implemented? Evan, If the console is running in a window, I presume you can use the FlashWindow(Ex) API. In newer OS's you can find the console window handle using the GetConsoleWindow API. For older OS's here's...