473,322 Members | 1,504 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.

manipulating XML in memory

45
Hi all,
I need to manipulate a XML document in memory and then save that document to the disk.
Can this be done??

Please suggest me a link or post some sample code.

Basically, I need to write some values to a xml document based on the user input.

Like a user may enter some text in a Text box. This value should be stored in a XML doc. residing in the memory.

When he clicks save this info or the doc gets saved to disk.

Many thanks.
May 18 '07 #1
14 4211
dorinbogdan
839 Expert 512MB
Please tell what language you are using (Java, C#, Javascript....?)
May 18 '07 #2
querry
45
Sorry a bit late...
I use C#

Thanks.
May 21 '07 #3
dorinbogdan
839 Expert 512MB
I would use XMLDocument.
See this link.
May 21 '07 #4
querry
45
Thanks dorinbogdan

Really helped a lot.

Now one more question. I am creating a XML file with the XMLDocument Class that has the tags to define a HTML table. It looks like this.

<Table ID=...>
<TR>
<TC>
<Data with some attributes />
</TC>
</TR>
</Table>

Now I need to recreate the table.

Can you suggest how I should do this??

Thanks.
May 22 '07 #5
dorinbogdan
839 Expert 512MB
See this link at the section Adding a Filled Child Element.
May 22 '07 #6
querry
45
See this link at the section Adding a Filled Child Element.
Thanks a lot dorinbogdan.
May 24 '07 #7
dorinbogdan
839 Expert 512MB
You are always welcome.

God bless you,
Dorin.
May 24 '07 #8
querry
45
Hi dorinbogdan, :)

Again a bit late.... but I have a problem. I am developing a web application that needs to manipulate XML files in memory. As of now I am Loading and Saving XML files in every event handler. Let me explain....

Expand|Select|Wrap|Line Numbers
  1. page_Init()
  2. {
  3.  //Load XML
  4.  ....
  5.  //Manipulate XML
  6.  ....
  7.  //Save XML
  8. }
  9.  
  10. page_load()
  11. {
  12.  //Load XML
  13.  ....
  14.  //Manipulate XML
  15.  ....
  16.  //Save XML
  17. }
  18.  
  19. Event_Handler1()
  20. {
  21.  //Load XML
  22.  ....
  23.  //Manipulate XML
  24.  ....
  25.  //Save XML
  26. }
  27.  
  28. Event_Handler2()
  29. {
  30.  //Load XML
  31.  ....
  32.  //Manipulate XML
  33.  ....
  34.  //Save XML
  35. }
I suppose that this causes as much disk activity because we are loading and saving XML file again and again. Which, (if my supposition is correct) will cause more time to load my pages between the postbacks. I am a bit confused :(. Please let me know if I am going in the right direction.

Regards and thanks.

P.S. Also I would appreciate if you can point me to a URL or post a code for manipulating XML in such a scenario. Thanks again.
Jun 13 '07 #9
dorinbogdan
839 Expert 512MB
You could use few public xml objects or strings that will keep the Xml data in memory too. Then, if is postback, it doesn't need to open again the XML file, just use the appropriate public object or load data from string.

Later, it may appear other suggestions too.

Dorin.
Jun 13 '07 #10
querry
45
Thanks very much. I will try and revert back.
Jun 14 '07 #11
querry
45
Hi Dorin,

I have gone through and found that the XML file needs to be stored in a Database. Can you suggest anything related to storing a XML file in a MS SQL Server 2000/2005 Database using C#.

Thanks very much.
Jun 19 '07 #12
dorinbogdan
839 Expert 512MB
In SQL 2005 there is a new data type: XML Data Type.
For SQL 2000 you should store the XML string in a Text data type field (not VarChar which is limited to 8000).

Then you can use ADO.NET to save / read the xml as a regular String.
Jun 19 '07 #13
querry
45
In SQL 2005 there is a new data type: XML Data Type.
For SQL 2000 you should store the XML string in a Text data type field (not VarChar which is limited to 8000).

Then you can use ADO.NET to save / read the xml as a regular String.

Thanks very much. I think, I need to do a bit of "googleing" on the topic.
Jun 21 '07 #14
querry
45
Ok fine I am able to save XML file into a database.

But, now I have another question. Something related to the XML namespaces.

I have a XML file of the following format.

Expand|Select|Wrap|Line Numbers
  1. <ns1:Table xmlns:ns1="http://something.com/ns1">
  2.     <ns1:TR> 
  3.            <ns1:TD >some text </ns1:TD>
  4.            <ns1:TD >some text </ns1:TD>
  5.            <ns1:TD >some text </ns1:TD>
  6.            <ns1:TD >some text </ns1:TD>
  7.      </ns1:TR>
  8. </ns1:Table>
I want to transform this XML Document using a .xsl file. I use something like this...

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3.  
  4. <xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/>
  5.  
  6. <xsl:template match="/">
  7.   <xsl:for-each select="//Table">
  8.     <HTML>
  9.       <HEAD><TITLE>Some Title</TITLE></HEAD>
  10.       <TABLE>
  11.           <xsl:apply-templates select="TR"/>
  12.       </TABLE>
  13.     </HTML>
  14.   </xsl:for-each>
  15. </xsl:template>
  16.  
  17. <xsl:template match="/TR">
  18.    <TR>
  19.            <xsl:apply-templates select="TD"/>
  20.    </TR>
  21. </xsl:template>
  22.  
  23. <xsl:template match="/TD">
  24.    <TD>
  25.            Some thing.......
  26.    </TD>
  27. </xsl:template>
  28.  
  29. </xsl:stylesheet>
How should I modify the above .xsl file so that I get the desired output.

Many thanks.
Jun 22 '07 #15

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

Similar topics

0
by: Tim Stone | last post by:
I'm working on a module that will manipulate large blobs. I'm using a C dll to allocate big blocks of memory, using PyMem_Malloc, which is working quite well up until I try to manipulate a blob...
10
by: Kristian Nybo | last post by:
Hi, I'm writing a simple image file exporter as part of a school project. To implement my image format of choice I need to work with big-endian bytes, where 'byte' of course means '8 bits', not...
5
by: Stijn van Dongen | last post by:
A question about void*. I have a hash library where the hash create function accepts functions unsigned (*hash)(const void *a) int (*cmp) (const void *a, const void *b) The insert function...
2
by: clojinted | last post by:
Hey, I want to break up a wav file using c# into smaller more managable chunks. I'm thinking a buffer to store part of the file may be the way to go. If anyone has any suggestions or could...
10
by: Segfahlt | last post by:
I have a fairly simple C# program that just needs to open up a fixed width file, convert each record to tab delimited and append a field to the end of it. The input files are between 300M and...
21
by: felixnielsen | last post by:
If im not mistaken, a char variable allocates 1 byte of memory, as it is the case with a bool variable. I need 2 bool and 1 char variable which only need to contain a value between 0 and 63...
8
by: brainflakes.org | last post by:
Hi guys, I need to manipulate binary data (8 bit) stored in a 2 dimensional array. I've tried various methods (arrays, using a string filled with chr(0), using gd lib) and so far the fastest...
2
by: Aaron Watters | last post by:
Poking around I discovered somewhere someone saying that Python gc adds a 4-7% speed penalty. So since I was pretty sure I was not creating reference cycles in nucular I tried running the tests...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.