I need to load a XML into a string. Is it possible and how do I do it?
I have a database using ODBC (MS SQL, P.SQL, Oracle.....) where the XML
file is stored as a TEXT type. I can load this field as a string type.
But I need to load this into a "XML reader", do any changes with the
XML doc and store it again into the database.
The database stuff is OK, I only need some help to load and save a XML
as a string type.
Can someone help me out here?
I have never used XML before. 8 2508
Firstly, you can't really load xml "into" an xml-reader, as it doesn't
actually store the data, it it just an efficient way of reading through xml
in a firehose fashion - i.e forwards only, read only.
If you want to manipulate the data (in a more convenient than string
manipulation) then you might want to look at XmlDocument; this is an object
that holds in memory the contents of the xml and allows for querying,
enumeration, changes etc - but the rub is that it takes a lot more memory,
because a: you need to hold the contents, and b: it is broken into objects,
rather than just being a string. If you go down this route, you can use the
LoadXml() method to populate it with your contents (from a string from the
db), and the OuterXml property to get the entire contents as a string.
Depending on the size of your data, you can also do this with streams - the
Load() method accepts (as one of the overloads) an input stream, and the
Save() method accepts an output stream.
The main warning, however: if your xml is alarmingly big (i.e. is
essentially an entire database), then the corresponding XmlDocument will be
even bigger.
Any use?
Marc
"GTi" <tu****@gmail.c om> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. . I need to load a XML into a string. Is it possible and how do I do it? I have a database using ODBC (MS SQL, P.SQL, Oracle.....) where the XML file is stored as a TEXT type. I can load this field as a string type. But I need to load this into a "XML reader", do any changes with the XML doc and store it again into the database.
The database stuff is OK, I only need some help to load and save a XML as a string type. Can someone help me out here? I have never used XML before.
Very simple example (not using xml-namespaces, schema, etc):
static void Main(string[] args) {
// (your code that gets the xml as a string from a text
column) - note the escaping is obviously not part of the xml
string xmlFromDatabase = "<Order><Cu st Name=\"Fred\"
ID=\"12345\"/><Item Line=\"1\" Code=\"123\" Price=\"1234.4\ "/></Order>";
// create a doc an load the contents from a string
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml FromDatabase);
// update the price of line 1
XmlElement line =
(XmlElement)doc .DocumentElemen t.SelectSingleN ode("Item[@Line=\"1\"]");
line.SetAttribu te("Price", "1500.00");
// retreive the updated contents as a string
string xmlToDatabase = doc.OuterXml;
// (your code that saves the xml as a string to a text column)
Console.WriteLi ne(xmlToDatabas e);
}
Marc
"Marc Gravell" <mg******@rm.co m> wrote in message
news:On******** ******@TK2MSFTN GP11.phx.gbl... Firstly, you can't really load xml "into" an xml-reader, as it doesn't actually store the data, it it just an efficient way of reading through xml in a firehose fashion - i.e forwards only, read only.
If you want to manipulate the data (in a more convenient than string manipulation) then you might want to look at XmlDocument; this is an object that holds in memory the contents of the xml and allows for querying, enumeration, changes etc - but the rub is that it takes a lot more memory, because a: you need to hold the contents, and b: it is broken into objects, rather than just being a string. If you go down this route, you can use the LoadXml() method to populate it with your contents (from a string from the db), and the OuterXml property to get the entire contents as a string. Depending on the size of your data, you can also do this with streams - the Load() method accepts (as one of the overloads) an input stream, and the Save() method accepts an output stream.
The main warning, however: if your xml is alarmingly big (i.e. is essentially an entire database), then the corresponding XmlDocument will be even bigger.
Any use?
Marc
"GTi" <tu****@gmail.c om> wrote in message news:11******** **************@ f14g2000cwb.goo glegroups.com.. .I need to load a XML into a string. Is it possible and how do I do it? I have a database using ODBC (MS SQL, P.SQL, Oracle.....) where the XML file is stored as a TEXT type. I can load this field as a string type. But I need to load this into a "XML reader", do any changes with the XML doc and store it again into the database.
The database stuff is OK, I only need some help to load and save a XML as a string type. Can someone help me out here? I have never used XML before.
Marc Gravell wrote: Very simple example (not using xml-namespaces, schema, etc):
static void Main(string[] args) { // (your code that gets the xml as a string from a text column) - note the escaping is obviously not part of the xml string xmlFromDatabase = "<Order><Cu st Name=\"Fred\" ID=\"12345\"/><Item Line=\"1\" Code=\"123\" Price=\"1234.4\ "/></Order>";
// create a doc an load the contents from a string XmlDocument doc = new XmlDocument(); doc.LoadXml(xml FromDatabase);
// update the price of line 1 XmlElement line = (XmlElement)doc .DocumentElemen t.SelectSingleN ode("Item[@Line=\"1\"]"); line.SetAttribu te("Price", "1500.00");
// retreive the updated contents as a string string xmlToDatabase = doc.OuterXml;
// (your code that saves the xml as a string to a text column) Console.WriteLi ne(xmlToDatabas e);
}
Marc
"Marc Gravell" <mg******@rm.co m> wrote in message news:On******** ******@TK2MSFTN GP11.phx.gbl... Firstly, you can't really load xml "into" an xml-reader, as it doesn't actually store the data, it it just an efficient way of reading through xml in a firehose fashion - i.e forwards only, read only.
If you want to manipulate the data (in a more convenient than string manipulation) then you might want to look at XmlDocument; this is an object that holds in memory the contents of the xml and allows for querying, enumeration, changes etc - but the rub is that it takes a lot more memory, because a: you need to hold the contents, and b: it is broken into objects, rather than just being a string. If you go down this route, you can use the LoadXml() method to populate it with your contents (from a string from the db), and the OuterXml property to get the entire contents as a string. Depending on the size of your data, you can also do this with streams - the Load() method accepts (as one of the overloads) an input stream, and the Save() method accepts an output stream.
The main warning, however: if your xml is alarmingly big (i.e. is essentially an entire database), then the corresponding XmlDocument will be even bigger.
Any use?
Marc
"GTi" <tu****@gmail.c om> wrote in message news:11******** **************@ f14g2000cwb.goo glegroups.com.. .I need to load a XML into a string. Is it possible and how do I do it? I have a database using ODBC (MS SQL, P.SQL, Oracle.....) where the XML file is stored as a TEXT type. I can load this field as a string type. But I need to load this into a "XML reader", do any changes with the XML doc and store it again into the database.
The database stuff is OK, I only need some help to load and save a XML as a string type. Can someone help me out here? I have never used XML before.
This looks easy.... but can you explain what this is:
..SelectSingleN ode("Item[@Line=\"1\"]");
What is "Item[@Line=\"1\"]"
^^^^^^^^
A MSDN sample use
"descendant::bo ok[author/last-name='Smith']"
^^^^^^^^^^^^^^^
What is the syntax for the parameter ?
> This looks easy.... but can you explain what this is: .SelectSingleNo de("Item[@Line=\"1\"]"); What is "Item[@Line=\"1\"]" ^^^^^^^^
A MSDN sample use "descendant::bo ok[author/last-name='Smith']" ^^^^^^^^^^^^^^^
What is the syntax for the parameter ?
I've never used the 'descendant' notation before... I've always just given
the name of the child element I am searching for and it has worked just
fine. I've also never had to use it with xml-namespaces, so it's possible
that may require some different usage.
--
Adam Clauss
The links in Jon's post should be your starting point, and note that the SDK
that comes with MSXML4 is also a lifeline...
However - to answer your question for the 2 examples:
Example 1 (mine)
..DocumentEleme nt.SelectSingle Node("Item[@Line=\"1\"]");
piece by piece:
..DocumentEleme nt - "from the root element, aka Order" - i.e. the outer
element in the xml
..SelectSingleN ode() - from the node in question (Order), evaluates an
expression, and returns the first matching element found (if any), else
returns null
The query is XPath; first we indicate which elements we are looking to
return (in this case the Item), then the conditions: anything in square
braces is essentially a "where" clause; @ means attribute, other element is
assumed; in English this would be "from the current node, look at the
immediate children called "Item" where they have an attribute "Line" with a
value of 1 (compared as a string)" - so the whole expression basically says
"Find the first /Order/Item with the Line attribute being 1"
Example 2 (MSDN)
descendant::boo k[author/last-name='Smith']
On its own, this doesn't tell me what the start point of the query is (which
is actually quite important); the double-colon here indicates an axis;
descendant is the axis that means "below this node, but at any level";
English interpretation of the query:
From the current context node (wherever that is) return all descendants
called "book" which themselves have an "author" element with a "last-name"
sub-element with the text value of "Smith"
As an example, if I evaluated the above query from the root node (somedata)
of the xml below, I would (without testing, so don't quote me) expect it to
return books 1 and 2, but not 3 (because the last-name is expressed as an
attribute, and the query only looks for elements called last-name).
<somedata>
<blah>
<book
id="1"><author> <last-name>Smith</last-name><last-name>Jones</last-name></author></book>
<something><boo k
id="2"><author> <last-name>Smith</last-name></author></book></something>
<book id="3"><author last-name="Smith"/></book></something>
</blah>
</somedata>
Marc
"GTi" <tu****@gmail.c om> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. . Marc Gravell wrote: Very simple example (not using xml-namespaces, schema, etc):
static void Main(string[] args) { // (your code that gets the xml as a string from a text column) - note the escaping is obviously not part of the xml string xmlFromDatabase = "<Order><Cu st Name=\"Fred\" ID=\"12345\"/><Item Line=\"1\" Code=\"123\" Price=\"1234.4\ "/></Order>";
// create a doc an load the contents from a string XmlDocument doc = new XmlDocument(); doc.LoadXml(xml FromDatabase);
// update the price of line 1 XmlElement line = (XmlElement)doc .DocumentElemen t.SelectSingleN ode("Item[@Line=\"1\"]"); line.SetAttribu te("Price", "1500.00");
// retreive the updated contents as a string string xmlToDatabase = doc.OuterXml;
// (your code that saves the xml as a string to a text column) Console.WriteLi ne(xmlToDatabas e);
}
Marc
"Marc Gravell" <mg******@rm.co m> wrote in message news:On******** ******@TK2MSFTN GP11.phx.gbl... > Firstly, you can't really load xml "into" an xml-reader, as it doesn't > actually store the data, it it just an efficient way of reading through > xml in a firehose fashion - i.e forwards only, read only. > > If you want to manipulate the data (in a more convenient than string > manipulation) then you might want to look at XmlDocument; this is an > object that holds in memory the contents of the xml and allows for > querying, enumeration, changes etc - but the rub is that it takes a lot > more memory, because a: you need to hold the contents, and b: it is > broken > into objects, rather than just being a string. If you go down this > route, > you can use the LoadXml() method to populate it with your contents > (from a > string from the db), and the OuterXml property to get the entire > contents > as a string. Depending on the size of your data, you can also do this > with > streams - the Load() method accepts (as one of the overloads) an input > stream, and the Save() method accepts an output stream. > > The main warning, however: if your xml is alarmingly big (i.e. is > essentially an entire database), then the corresponding XmlDocument > will > be even bigger. > > Any use? > > Marc > > "GTi" <tu****@gmail.c om> wrote in message > news:11******** **************@ f14g2000cwb.goo glegroups.com.. . >>I need to load a XML into a string. Is it possible and how do I do it? >> I have a database using ODBC (MS SQL, P.SQL, Oracle.....) where the >> XML >> file is stored as a TEXT type. I can load this field as a string type. >> But I need to load this into a "XML reader", do any changes with the >> XML doc and store it again into the database. >> >> The database stuff is OK, I only need some help to load and save a XML >> as a string type. >> Can someone help me out here? >> I have never used XML before. >> > >
This looks easy.... but can you explain what this is: .SelectSingleNo de("Item[@Line=\"1\"]"); What is "Item[@Line=\"1\"]" ^^^^^^^^
A MSDN sample use "descendant::bo ok[author/last-name='Smith']" ^^^^^^^^^^^^^^^
What is the syntax for the parameter ?
The links in Jon's post should be your starting point, and note that the SDK
that comes with MSXML4 is also a lifeline...
However - to answer your question for the 2 examples:
Example 1 (mine)
..DocumentEleme nt.SelectSingle Node("Item[@Line=\"1\"]");
piece by piece:
..DocumentEleme nt - "from the root element, aka Order" - i.e. the outer
element in the xml
..SelectSingleN ode() - from the node in question (Order), evaluates an
expression, and returns the first matching element found (if any), else
returns null
The query is XPath; first we indicate which elements we are looking to
return (in this case the Item), then the conditions: anything in square
braces is essentially a "where" clause; @ means attribute, other element is
assumed; in English this would be "from the current node, look at the
immediate children called "Item" where they have an attribute "Line" with a
value of 1 (compared as a string)" - so the whole expression basically says
"Find the first /Order/Item with the Line attribute being 1"
Example 2 (MSDN)
descendant::boo k[author/last-name='Smith']
On its own, this doesn't tell me what the start point of the query is (which
is actually quite important); the double-colon here indicates an axis;
descendant is the axis that means "below this node, but at any level";
English interpretation of the query:
From the current context node (wherever that is) return all descendants
called "book" which themselves have an "author" element with a "last-name"
sub-element with the text value of "Smith"
As an example, if I evaluated the above query from the root node (somedata)
of the xml below, I would (without testing, so don't quote me) expect it to
return books 1 and 2, but not 3 (because the last-name is expressed as an
attribute, and the query only looks for elements called last-name).
<somedata>
<blah>
<book
id="1"><author> <last-name>Smith</last-name><last-name>Jones</last-name></author></book>
<something><boo k
id="2"><author> <last-name>Smith</last-name></author></book></something>
<book id="3"><author last-name="Smith"/></book></something>
</blah>
</somedata>
Marc
"GTi" <tu****@gmail.c om> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. . Marc Gravell wrote: Very simple example (not using xml-namespaces, schema, etc):
static void Main(string[] args) { // (your code that gets the xml as a string from a text column) - note the escaping is obviously not part of the xml string xmlFromDatabase = "<Order><Cu st Name=\"Fred\" ID=\"12345\"/><Item Line=\"1\" Code=\"123\" Price=\"1234.4\ "/></Order>";
// create a doc an load the contents from a string XmlDocument doc = new XmlDocument(); doc.LoadXml(xml FromDatabase);
// update the price of line 1 XmlElement line = (XmlElement)doc .DocumentElemen t.SelectSingleN ode("Item[@Line=\"1\"]"); line.SetAttribu te("Price", "1500.00");
// retreive the updated contents as a string string xmlToDatabase = doc.OuterXml;
// (your code that saves the xml as a string to a text column) Console.WriteLi ne(xmlToDatabas e);
}
Marc
"Marc Gravell" <mg******@rm.co m> wrote in message news:On******** ******@TK2MSFTN GP11.phx.gbl... > Firstly, you can't really load xml "into" an xml-reader, as it doesn't > actually store the data, it it just an efficient way of reading through > xml in a firehose fashion - i.e forwards only, read only. > > If you want to manipulate the data (in a more convenient than string > manipulation) then you might want to look at XmlDocument; this is an > object that holds in memory the contents of the xml and allows for > querying, enumeration, changes etc - but the rub is that it takes a lot > more memory, because a: you need to hold the contents, and b: it is > broken > into objects, rather than just being a string. If you go down this > route, > you can use the LoadXml() method to populate it with your contents > (from a > string from the db), and the OuterXml property to get the entire > contents > as a string. Depending on the size of your data, you can also do this > with > streams - the Load() method accepts (as one of the overloads) an input > stream, and the Save() method accepts an output stream. > > The main warning, however: if your xml is alarmingly big (i.e. is > essentially an entire database), then the corresponding XmlDocument > will > be even bigger. > > Any use? > > Marc > > "GTi" <tu****@gmail.c om> wrote in message > news:11******** **************@ f14g2000cwb.goo glegroups.com.. . >>I need to load a XML into a string. Is it possible and how do I do it? >> I have a database using ODBC (MS SQL, P.SQL, Oracle.....) where the >> XML >> file is stored as a TEXT type. I can load this field as a string type. >> But I need to load this into a "XML reader", do any changes with the >> XML doc and store it again into the database. >> >> The database stuff is OK, I only need some help to load and save a XML >> as a string type. >> Can someone help me out here? >> I have never used XML before. >> > >
This looks easy.... but can you explain what this is: .SelectSingleNo de("Item[@Line=\"1\"]"); What is "Item[@Line=\"1\"]" ^^^^^^^^
A MSDN sample use "descendant::bo ok[author/last-name='Smith']" ^^^^^^^^^^^^^^^
What is the syntax for the parameter ? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ben beroukhim |
last post by:
I have huge number of legacy code which use standard files functions.
I would like to pass a memory pointer rather than a FILE pointer.
I am trying to use FILEs in the code to refer to memory buffers.
Basically, I want to be able to use all the standard read and write
functions, but I want them to refer to memory locations, rather than
disk
files.
I do not want to touch the legacy code. Does any one know of a library
|
by: JW |
last post by:
I can encrypt the contents of a memory stream with no problems, however when
decrypting( I'm using the same key an IV ) I get an exception stating bad
data.
I'm at a lost. I'm actually creating a new memory stream, filling it with
the encrypted bytes then trying to read from the crypto stream object. I
have used the same approach encrypting to a file handle and then decrypting
from the same file and it works.
|
by: Tomaz Koritnik |
last post by:
Hi
I have many short HTML files stored in a binary stream storage to display
descriptions for various items in application. HTML would be display inside
application using some .NET control or COM control (like Microsoft
WebBrowser). For each description there is one HTML file and along
description text, it contains links to related information. Clicking related
information would for example open new form in application and display some...
|
by: SDS |
last post by:
I am writing an ASP.NET application (in C#) that, as part of a
particular response, populates a MemoryStream object with binary data
that is being collected from a Process object's StandardOutput. This
data can be between 60MB and 100MB under normal circumstances. I write
this data to the response stream.
I'm noticing that calls to this particular page are causing W3WP to use
upwards of 60MB. When W3WP starts up, its using around 24MB...
|
by: ad |
last post by:
I used use SharpZipLib to compress files in disk.
But now I want to compress stream into another stream in memory(the stream
not associated with disk file)
My pseudo is:
Stream InputStream;
Stream OutPutStream;
DataSet1.WriteXml(InputStream);
| |
by: chance |
last post by:
Hello,
I have a file on disk called TEMP.ZIP and I would like to somehow get
this into a memory stream so I can eventually do this:
row = dataStream.ToArray()
However, I am not sure of the correct way to get it into a memory
stream.
Any help appreciated.
|
by: Kane |
last post by:
When you create node 1 you allocate memory and link it Again when you
create node 2 you would allocate memory for that node in a different
section of the code. Is there more efficient way where I can allocate
memory once and use it to create new node in list.
-Thanks
-Kane
|
by: phreak008 |
last post by:
I'm using SendMessage(...) to send a message to all other process that might run. It works well. My problem is when I try to pass data using shared memory. Here is my code.
In the 1st process, I use this to send the msg
BinaryFormatter b = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
b.Serialize(stream, str);
stream.Flush();
int dataSize =(int)...
|
by: CSharper |
last post by:
I have a resource file that i open to write.After writing almost 300MB
I call the close method and It failed with out of memory. One thing I
learned that, in C#, resource writers doesn't write data directly to
disk instead it writes to memory and then at the end on either close/
dispose, it will write the data to disk. I am thinking of compressing
the data still, I will grow into the size very fast.
Is there an alternate solution to this?...
|
by: Nitin Mahajan |
last post by:
Guys
Is there a way in C# to create a word object directly from a memory
stream without passing that to hard disk (file stream). I think it
doesn't makes sense to create a file just to read it again in to word
object. If some one has some brilliant idea please share.
In a nutshell this is what I'm currently doing
ByteArray --File Stream --Word Object
and this I want to do
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
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...
|
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,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |