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

Howto: format attribtes per line rather then on one line

Hi All,

Using the XmlDocument and XMLElement::SetAttribute
is there away to indent the attribute per line, rather hen them having them
on the one line
e.g
<MyRoot Att1="Value1" Att2="Value2"></MyRoot>
but
<MyRoot
Att1="Value1"
Att2="Value2"

</MyRoot>
Cheers,
Fred

Nov 12 '05 #1
4 1739


Fred Heida wrote:

Using the XmlDocument and XMLElement::SetAttribute
is there away to indent the attribute per line, rather hen them having them
on the one line
e.g
<MyRoot Att1="Value1" Att2="Value2"></MyRoot>
but
<MyRoot
Att1="Value1"
Att2="Value2"

</MyRoot>


I do not see anything in .NET 1.1 that would allow that, the
documentation for XmlTextWriter explicitly says that indentation applies to

DocumentType
Element
Kommentar
ProcessingInstruction
CDATASection

only.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Thx Martin,

Cheers,
Fred

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...


Fred Heida wrote:

Using the XmlDocument and XMLElement::SetAttribute
is there away to indent the attribute per line, rather hen them having them on the one line
e.g
<MyRoot Att1="Value1" Att2="Value2"></MyRoot>
but
<MyRoot
Att1="Value1"
Att2="Value2"

</MyRoot>
I do not see anything in .NET 1.1 that would allow that, the
documentation for XmlTextWriter explicitly says that indentation applies

to
DocumentType
Element
Kommentar
ProcessingInstruction
CDATASection

only.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #3
Fred Heida wrote:
Using the XmlDocument and XMLElement::SetAttribute
is there away to indent the attribute per line, rather hen them having them
on the one line
e.g
<MyRoot Att1="Value1" Att2="Value2"></MyRoot>
but
<MyRoot
Att1="Value1"
Att2="Value2"

</MyRoot>


You can create custom XmlWriter to workaround it:

public class AttributeIndentingXmlTextWriter : XmlTextWriter
{
private TextWriter w;
private int depth;

//Add constructors as needed
public AttributeIndentingXmlTextWriter(TextWriter w)
: base(w)
{
this.w = w;
}

public override void WriteStartElement(string prefix, string
localName, string ns)
{
depth ++;
base.WriteStartElement(prefix, localName, ns);
}

public override void WriteFullEndElement()
{
depth--;
base.WriteFullEndElement();
}

public override void WriteEndElement()
{
depth--;
base.WriteEndElement();
}

public override void WriteStartAttribute(string prefix, string
localName, string ns)
{
if (base.Formatting == Formatting.Indented)
{
w.WriteLine();
for (int i=1; i<Indentation*depth; i++)
w.Write(IndentChar);
}
base.WriteStartAttribute(prefix, localName, ns);
}
}

Then save XmlDocument via instance of an AttributeIndentingXmlTextWriter.
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #4
Hi Oleg,

Works great! thx!!

Cheers,

Fred

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:ON**************@tk2msftngp13.phx.gbl...
Fred Heida wrote:
Using the XmlDocument and XMLElement::SetAttribute
is there away to indent the attribute per line, rather hen them having them on the one line
e.g
<MyRoot Att1="Value1" Att2="Value2"></MyRoot>
but
<MyRoot
Att1="Value1"
Att2="Value2"

</MyRoot>


You can create custom XmlWriter to workaround it:

public class AttributeIndentingXmlTextWriter : XmlTextWriter
{
private TextWriter w;
private int depth;

//Add constructors as needed
public AttributeIndentingXmlTextWriter(TextWriter w)
: base(w)
{
this.w = w;
}

public override void WriteStartElement(string prefix, string
localName, string ns)
{
depth ++;
base.WriteStartElement(prefix, localName, ns);
}

public override void WriteFullEndElement()
{
depth--;
base.WriteFullEndElement();
}

public override void WriteEndElement()
{
depth--;
base.WriteEndElement();
}

public override void WriteStartAttribute(string prefix, string
localName, string ns)
{
if (base.Formatting == Formatting.Indented)
{
w.WriteLine();
for (int i=1; i<Indentation*depth; i++)
w.Write(IndentChar);
}
base.WriteStartAttribute(prefix, localName, ns);
}
}

Then save XmlDocument via instance of an AttributeIndentingXmlTextWriter.
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #5

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

Similar topics

4
by: Logan | last post by:
Several people asked me for the following HOWTO, so I decided to post it here (though it is still very 'alpha' and might contain many (?) mistakes; didn't test what I wrote, but wrote it - more or...
1
by: Gernot Hillier | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi! I'm the developer of a Linux ISDN application which uses embedded Python for controlling the communication. It starts several threads (i.e....
7
by: flamesrock | last post by:
Hi, As a newbie to the language, I have no idea where to start..please bare with me.. The simcity 4 savegame file has a png image stored at the hex location 0x80. What I want to extract it...
10
by: Jack | last post by:
Hi, I cannot get the date format correctly in dynamic sql statement, after trying various ways of handling it. I need some help with the date format in the following dynamic sql statement. Any...
4
by: intl04 | last post by:
I have a memo field that is included in some Access reports I created. Is there some way for the memo field to display nicely formatted text, with line breaks between paragraphs? Or is it necessary...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
7
by: Sobhan | last post by:
Hi all, Iam writing a small C program to print a array of numbers in Comma Separated Values in VC++ editor. Lets say: Title Title1 Title2 ----- ------ ------ 10,20,30 50,90,100 120,180,300
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
6
by: Ian Boyd | last post by:
Every time during development we had to make table changes, we use Control Center. Most of the time, Control Center fails. If you try to "undo all", it doesn't, and you end up losing your identity...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.