473,625 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create xml with formatting

cnu
Hi,
I have to make a formatted (indented) xml file like this :

<?xml version="1.0"?>
<Message>
<Parent index="0" length="6">123
<Child1 index="0,1" length="6">abcd </Child1>
<Child2 index="0,2" length="6">pqrs xyz</Child2>
</Parent>
</Message>

As you can see, <Parent> node has some innertext as well as child nodes.
But, if
I make xml like this the indentation is lost. The resultant xml is like
this :

<?xml version="1.0"?>
<Message>
<Parent index="0" length="6">123< Child1 index="0,1"
length="6">99</Child1><Child2 index="0,2" length="6">pqrs xyz</Child2></Parent>
</Message>

To sum up the problem, if a node has both innertext and some child nodes,
then the entire node is written in a single line, without indentation.
How can I get the indentation in the above case??
Any help is highly appreciated.

Thanks.
Aug 25 '05 #1
5 2160
Is that even valid XML?
"cnu" <cn*@discussion s.microsoft.com > wrote in message
news:59******** *************** ***********@mic rosoft.com...
Hi,
I have to make a formatted (indented) xml file like this :

<?xml version="1.0"?>
<Message>
<Parent index="0" length="6">123
<Child1 index="0,1" length="6">abcd </Child1>
<Child2 index="0,2" length="6">pqrs xyz</Child2>
</Parent>
</Message>

As you can see, <Parent> node has some innertext as well as child nodes.
But, if
I make xml like this the indentation is lost. The resultant xml is like
this :

<?xml version="1.0"?>
<Message>
<Parent index="0" length="6">123< Child1 index="0,1"
length="6">99</Child1><Child2 index="0,2"
length="6">pqrs xyz</Child2></Parent>
</Message>

To sum up the problem, if a node has both innertext and some child nodes,
then the entire node is written in a single line, without indentation.
How can I get the indentation in the above case??
Any help is highly appreciated.

Thanks.

Aug 25 '05 #2
cnu
Though the format looks weird, it is a valid xml.
Unfortunately, I can't change the format...

Aug 25 '05 #3
On Wed, 24 Aug 2005 19:26:02 -0700, cnu wrote:

Hi!
To sum up the problem, if a node has both innertext and some child nodes,
then the entire node is written in a single line, without indentation.
How can I get the indentation in the above case??


You forgot to tell how you create the XML, I _assume_ you use
System.Xml.XmlW riter. In such case try it's 'Formating' property:

xmlWriter.Forma tting = System.Xml.Form atting.Indented ;

Cheers,
Piotrek

Aug 25 '05 #4
cnu
I have all the xml in XmlDocument and this is how I save :

System.Xml.XmlT extWriter xtw = new XmlTextWriter(a FilePath, null);
xtw.Formatting = Formatting.Inde nted;
xmlDoc.Save(xtw );
xtw.Flush();
xtw.Close();
Aug 25 '05 #5
On Thu, 25 Aug 2005 00:41:02 -0700, cnu wrote:

Hi!
System.Xml.XmlT extWriter xtw = new XmlTextWriter(a FilePath, null);
xtw.Formatting = Formatting.Inde nted;
xmlDoc.Save(xtw );
xtw.Flush();
xtw.Close();


It looks like you have found a bug in .NET XmlWriter :/
The code below seems to proove it... Any MVP here?

// --- the code ---
System.Xml.XmlT extWriter xtw = new XmlTextWriter(@ "c:\temp\aTest. xml", System.Text.Enc oding.UTF8);
xtw.Formatting = Formatting.Inde nted;

xtw.WriteStartE lement("Message ");
xtw.WriteStartE lement("Parent" );
xtw.WriteAttrib uteString("Inde x", "0");
xtw.WriteAttrib uteString("Leng th", "6");
xtw.WriteString ("123"); // get rid of this line and everything is ok

xtw.WriteStartE lement("Child1" );
xtw.WriteAttrib uteString("inde x", "0,1");
xtw.WriteAttrib uteString("leng th", "6");
xtw.WriteString ("abcd");

xtw.WriteEndEle ment();
xtw.WriteEndEle ment();
xtw.WriteEndEle ment();

xtw.Flush();
xtw.Close();
// --- end ---

Cheers,
Piotrek

Aug 25 '05 #6

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

Similar topics

3
5380
by: Richard Fritzler | last post by:
I was given the task of designing a complete web based document prep system. In simplest terms (using a msword explanation) create a database of merge fields, and a library of templates. Allow the webuser to select the template, merge his DB record, and produce a formatted document that can be printed or downloaded. We need to do this without specialized software on the client, since it will be universally available to webusers. We...
2
2602
by: Terry | last post by:
I have cerated a Form, ExamsFrm, which is used to input details of exams taken at several Centres. It dosplays details from StudentTbl and has a SubForm which displays details from ExamsTble. I have incorporated some VB6 code as well as some Conditional Formatting. The code automatically updates CheckBoxes in the SubForm, depending on exam results, and the Conditional Formatting changes background colours, depending on CheckBox datum. ...
1
4301
by: Mike P | last post by:
I am trying to create a new file and write to it, but I keep getting the error 'cannot access the file because it is being used by another process'. Can anybody help me out? long lngNextNumber = Find_Next_File_Number(); string strNewFile = "C:\\inetpub\\wwwroot\\webapplication90\\xml_files\\test" + lngNextNumber + ".xml"; File.Create(strNewFile);
2
1053
by: ALI-R | last post by:
Hi All, I have an xml file with the structure below.I'd like to create dynamic number of xml files from this file based on <subreport> elements.each XML file contains subreport element only .for instance if there are 4 <subreport> elements ,I'd like to create 4 different xml files and I want them to be named based on <Ship_Via> child value in each <subreport> element. Is there somebody who can give me an idea?
5
305
by: cnu | last post by:
Hi, I have to make a formatted (indented) xml file like this : <?xml version="1.0"?> <Message> <Parent index="0" length="6">123 <Child1 index="0,1" length="6">abcd</Child1> <Child2 index="0,2" length="6">pqrsxyz</Child2> </Parent> </Message>
4
12427
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
4
1156
by: pankajit09 | last post by:
Hello, How to create the formatting area which you see while composing an email ? The formatting area consist of the Bold, Italics, Underline etc.
0
1080
by: remya1000 | last post by:
i'm using VB.NET. i'm using this codes to create this XML. TextBox1.Text = "C:\Program\Emp.mdb" If File.Exists(TextBox1.Text) Then Dim strSQL As String = "Select ItemID,pl11,pl12 from MG10 where ItemID <> 0" Dim myConnection As New OleDbConnection(strConn)
2
5237
by: DragonLord | last post by:
Ok basically this is mostly working, What i want to do is create an xml file with multiple updates that have the same attribute. <root> <update> <element1>value</element1> <element2>value</element2> <element3>value</element3> <element4>value</element4>
0
8692
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
8635
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
8354
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
8497
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...
1
6116
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1499
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.