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

How do you remove and insert xml in C#

grs
All,

In the xml document below I want to delete the <eConnectProcessInfo
xsi:nil="true" />
and insert
<eConnectProcessInfo>
<ConnectionString>data source=SERVERName ...etc</ConnectionString>
</eConnectProcessInfo?

Will someone please give me some C# code to accomplish the task.

thanks
grs
==========
<?xml version="1.0"?>
<eConnect xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<GLTransactionType>
<eConnectProcessInfo xsi:nil="true" />
<taGLTransactionLineInsert_Items>
<taGLTransactionLineInsert>
<BACHNUMB>BATCHNBR123</BACHNUMB>
<JRNENTRY>1000001</JRNENTRY>
<CRDTAMNT>2.50</CRDTAMNT>
<DEBITAMT>0</DEBITAMT>
<ACTNUMST>00-0000-10700-0000-0000</ACTNUMST>
</taGLTransactionLineInsert>
<taGLTransactionLineInsert>
<BACHNUMB>BATCHNBR123</BACHNUMB>
<JRNENTRY>1000001</JRNENTRY>
<CRDTAMNT>0</CRDTAMNT>
<DEBITAMT>2.50</DEBITAMT>
<ACTNUMST>00-1000-60100-0000-EBAY</ACTNUMST>
</taGLTransactionLineInsert>
</taGLTransactionLineInsert_Items>
<taGLTransactionHeaderInsert>
<BACHNUMB>BATCHNBR123</BACHNUMB>
<JRNENTRY>1000001</JRNENTRY>
<REFRENCE>AAA000000009</REFRENCE>
<TRXDATE>2005-05-10</TRXDATE>
<TRXTYPE>0</TRXTYPE>
</taGLTransactionHeaderInsert>
<taMdaUpdate_Items xsi:nil="true" />
</GLTransactionType>
</eConnect>
Nov 15 '05 #1
4 10275
Hi grs,

The easiest way is using DOM. Assumming that you have loaded that xml
document (using XmlDocument.Load, or XmlDocument.LoadXml).
In the xml document below I want to delete XmlElement root = xmlDoc.DocumentElement;
root.RemoveChild(root.SelectSingleNode("eConnectPr ocessInfo");
and insert

XmlElement node1 = xmlDoc.CreateElement("eConnectProcessInfo");
XmlElement node2 = xmlDoc.CreateElement("ConnectionString");
node2.InnerText = "data source=SERVERName ...etc";
node1.AppendChild(node2);
root.AppendChild(node1);

You can also use root.ReplaceChild for your purpose. You can also
remove the "xsi:nil" attribute and append the "ConnectionString"
element only.

Further info could be found in .NET documentation.

Thi.

Nov 16 '05 #2
Hi grs,

You can load the whole document into an XmlDocument object and add/remove
nodes in it. You can try to following code snippet to achieve this. I
tested it on my machine and it works fine.

XmlDocument doc = new XmlDocument();
doc.Load(@"e:\test1.xml");
XmlNode n =
doc.SelectSingleNode("//eConnect/GLTransactionType/eConnectProcessInfo");
n.RemoveAll();
XmlElement newElem = doc.CreateElement("ConnectionString");
newElem.InnerText = "data source=SERVERName ...etc";
n.AppendChild(newElem);

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3
grs
Truong and Kevin,
Thank you !
grs

"grs" <gs****@budgetext.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
All,

In the xml document below I want to delete the <eConnectProcessInfo
xsi:nil="true" />
and insert
<eConnectProcessInfo>
<ConnectionString>data source=SERVERName ...etc</ConnectionString>
</eConnectProcessInfo?

Will someone please give me some C# code to accomplish the task.

thanks
grs
==========
<?xml version="1.0"?>
<eConnect xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<GLTransactionType>
<eConnectProcessInfo xsi:nil="true" />
<taGLTransactionLineInsert_Items>
<taGLTransactionLineInsert>
<BACHNUMB>BATCHNBR123</BACHNUMB>
<JRNENTRY>1000001</JRNENTRY>
<CRDTAMNT>2.50</CRDTAMNT>
<DEBITAMT>0</DEBITAMT>
<ACTNUMST>00-0000-10700-0000-0000</ACTNUMST>
</taGLTransactionLineInsert>
<taGLTransactionLineInsert>
<BACHNUMB>BATCHNBR123</BACHNUMB>
<JRNENTRY>1000001</JRNENTRY>
<CRDTAMNT>0</CRDTAMNT>
<DEBITAMT>2.50</DEBITAMT>
<ACTNUMST>00-1000-60100-0000-EBAY</ACTNUMST>
</taGLTransactionLineInsert>
</taGLTransactionLineInsert_Items>
<taGLTransactionHeaderInsert>
<BACHNUMB>BATCHNBR123</BACHNUMB>
<JRNENTRY>1000001</JRNENTRY>
<REFRENCE>AAA000000009</REFRENCE>
<TRXDATE>2005-05-10</TRXDATE>
<TRXTYPE>0</TRXTYPE>
</taGLTransactionHeaderInsert>
<taMdaUpdate_Items xsi:nil="true" />
</GLTransactionType>
</eConnect>

Nov 16 '05 #4
You're welcome.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #5

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

Similar topics

8
by: JT | last post by:
i have written some asp that reads a fixed length text file, line by line, inserting each line into my database. my problem is that the text file format seems to have extra space at the end of the...
3
by: Diego Rey | last post by:
Hi everyone. How can I get the unique row from a table which contains multiple rows that have exactly the same values. example: create table test ( c1 as smallint, c2 as smallint, c3 as...
12
by: laurenq uantrell | last post by:
Is there an easy way to loop through all rows and remove all international alphabet characters from a column in a table, for example remove German umlauts "" and convert them to a simple "u"....
6
by: Arne Claus | last post by:
Hi If've just read, that remove() on a list does not actually remove the elements, but places them at the end of the list (according to TC++STL by Josuttis). It also says, that remove returns a...
7
by: sanjana | last post by:
hi i wanna detect if a anything is connected to the usb port I am using system.management class for tht purpose this is my code class usbdetect { public static void Main() {
1
by: Glenn | last post by:
Hi, I have a config XML file that I am using from the application cache. I have configured the entry with a remove callback to re-populate cache automatically when the XML file changes. All is...
3
by: Markus | last post by:
Hi! I wanted to select a subset of nodes (list = selectNodes("parent/child") from a XmlDocument, then remove all (parentNode.removeAll();) child-nodes and insert the previous selected nodes...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
3
by: Yas | last post by:
Hi, I am creating creating a table with a Date column dd-mm-yyyy. But I cant seem to find a SQL function that just returns today's date. getDate() returns the time as well so I cant use it. ...
1
by: pipetawer | last post by:
Greetings, I am having some kind of trouble with some code. I have the following object using System; using System.Collections; namespace ImageServerCleanup { public class DiffList :...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
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...
0
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,...
0
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...
0
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...

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.