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

Create A XML doc

scriptick
I use this code -
Expand|Select|Wrap|Line Numbers
  1.  XmlWriterSettings settings = new
  2. XmlWriterSettings();
  3. settings.Indent = true;
  4. settings.IndentChars = (" " );
  5. settings.CloseOutput = true;
  6. settings.OmitXmlDeclaration = true;
  7. using (XmlWriter writer = XmlWriter.Create
  8. ("books.xml" , settings))
  9. {
  10. writer.WriteStartElement( "book" );
  11. writer.WriteElementString( "title" , book.Title);
  12. writer.WriteElementString( "author" ,
  13. book.Author.Name);
  14. writer.WriteElementString( "publisher" ,
  15. book.Publisher);
  16. writer.WriteElementString( "price" ,
  17. book.Price.ToString());
  18. writer.WriteEndElement();
  19. writer.Flush();
  20. }
  21.  
  22. output in pavel.xml is 
  23.  
  24. <book>
  25. .....
  26. ........
  27. </book>
  28.  
  29. but I wanna output 
  30.  
  31. <book Key ="A">
  32. ....
  33. ...
  34. ...
  35. </book>
Just this. nothing else.

How to do this?
Oct 6 '13 #1

✓ answered by Joseph Martell

Those extra pieces of information found in the opening tags of XML are called attributes. You need to look into the WriteAttributeString method of XmlWriter.

After your line 10 you would need an extra line of code like this:

Expand|Select|Wrap|Line Numbers
  1. writer.WriteStartElement( "book" );
  2. writer.WriteAttributeString("Key", "A");
  3.  
Check out the documentation here (MSDN documentation for WriteAttributeString)

2 1319
Joseph Martell
198 Expert 128KB
Those extra pieces of information found in the opening tags of XML are called attributes. You need to look into the WriteAttributeString method of XmlWriter.

After your line 10 you would need an extra line of code like this:

Expand|Select|Wrap|Line Numbers
  1. writer.WriteStartElement( "book" );
  2. writer.WriteAttributeString("Key", "A");
  3.  
Check out the documentation here (MSDN documentation for WriteAttributeString)
Oct 7 '13 #2
Joseph Martell thanks a lot!
this is that what I am looking for!
Oct 7 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
4
by: I_AM_DON_AND_YOU? | last post by:
There is one more problem I am facing but didn't get the solution. In my Setup Program I am not been able to create 2 things (when the program is intalled on the client machine ) : (1) create...
10
by: Zack Sessions | last post by:
Has anyone tried to create a SQL7 view using the CREATE VIEW command and ADO.NET? If so, is there a trick in trapping a SQL error when trying to create the view? I have a VB.NET app that, amoung...
9
by: Peter | last post by:
Hello£¬everyone, My program will collect a testing machine's data ,save the data and deal with the data everyday. I want to use vb.net to create database, add and delete tables or modify the...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
5
by: Michael | last post by:
Hello, I've created an ASP web page where users in our organization can create Active Directory computer accounts. The web page is running on a Server 2003 SP1 IIS 6 installation. The...
8
by: barb | last post by:
So that the world at large benefits from our efforts, here is one fully documented way to use Windows Irfanview freeware to create thumbnail web galleries (http://www.irfanview.com). STEP 1:...
4
by: JohnnyDeep | last post by:
I am trying to create a store proc that contain a create index with the cluster option and I receive DB21034E The command was processed as an SQL statement because it was not a valid Command...
4
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...
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
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.