473,432 Members | 1,694 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,432 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 4222
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...
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...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.