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

Urgent Help on XmlDocument

Dear all,

I'm newbie to XML in C#. Below it's the existing XMLDocument I need to
generate using System.Xml. The <CustData> will loop thru a recordset to
generate it.

Example Codes :-

XmlDeclaration xmlDeclaration =
xmlDoc.CreateXmlDeclaration("1.0","utf-8",null);
XmlElement rootNode = xmlDoc.CreateElement("Customers");
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
xmlDoc.AppendChild(rootNode);

XmlDocument SubNodes = new XmlDocument ();
string strStruc = "<CustData><CustName></CustName><Desc></Desc></CustData>";
SubNodes.LoadXml(strStruc);

XmlNodeList XmlRootNode = xmlDoc.GetElementsByTagName("Customers");
XmlNodeList docSubNode = SubNodes.GetElementsByTagName("CustData");
XmlNodeList CustNameNode = xmlDoc.GetElementsByTagName("CustName");
XmlNodeList DescNode = xmlDoc.GetElementsByTagName("Desc");

//Loop RecordSet
if (colPE.Count > 0 )
{
for (int i = 0; i < colPE.Count; i++)
{
XmlRootNode.Item(0).AppendChild(xmlDoc.ImportNode( docSubNode
..Item(0).Clone() ,true)) ;
CustNameNode.Item(i).InnerText = colPE.Item(i).CustName.ToString().Trim();
DescNode.Item(i).InnerText = colPE.Item(i).Desc.ToString();
}
SubNodes = null;
}

Example XMLDocument:-

<Customers>
<CustData>
<CustName>123</CustName>
<Desc>TESTING</Desc>
</CustData>
<CustData>
<CustName>789</CustName>
<Desc>TESTING 123</Desc>
</CustData>
</Customers>

Further enhance the XmlDocument, I need to loop thru <CustData> and add in
the <TelephoneData> in the tag. I need to loop thru another recordset to get
<TelephoneData> for each customer.

Example XmlDocument :-

<Customers>
<CustData>
<CustName>123</CustName>
<Desc>TESTING</Desc>
<TelephoneData>
<TelDesc>Office</TelDesc>
<TelNumber>12345678</TelNumber>
</TelephoneData>
<TelephoneData>
<TelDesc>Home</TelDesc>
<TelNumber>12345678</TelNumber>
</TelephoneData>
</CustData>
<CustData>
<CustName>789</CustName>
<Desc>TESTING 123</Desc>
<TelephoneData>
<TelDesc>Home</TelDesc>
<TelNumber>456487987</TelNumber>
</TelephoneData>
</CustData>
</Customers>

The problem is, how to add in the additional <TelephoneData> into <CustData>
? Need example code on this.

Thank in advance.
Cheers,
Mae
Nov 21 '05 #1
0 1255

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

Similar topics

1
by: Aliandro | last post by:
Hi I am really stuck and need some expertise help please. I have an XML file: <XML> <USER_INFO> <USERNAME>username</USERNAME> <PASSWORD>password%</PASSWORD> </USER_INFO> <SITE_INFO>...
1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
2
by: Graham Pengelly | last post by:
Hi I am trying to transform on System.Xml.XmlDocument into another using XslTransform without writing the object out to a file. I am guessing it should work something like this... public...
1
by: Yama | last post by:
Hi, I am writing a windows form that will query the database. string query = "SELECT TOP 2 * FROM Northwind.dbo.Customers" ; DBQuery Q = new DBQuery() ; bool result =...
3
by: John Lee | last post by:
Hi, I have a document <root> <name>John</name> </root> and the xpath "//name" will return correct node by using xmldoc.SelectSingleNode(xpath) and if the document contains a default...
0
by: Björn Bengtsson | last post by:
Hello! I have an urgent problem concerning ASP.NET, ADO.NET, SQL Server, XML and the TreeView control. I have two tables; one describing the products and one describing their relationships. A...
5
by: SeanT | last post by:
Greetings and salutations! I am having a real issue with the VB.NET TreeView control. I need to display an image (a.k.a. logo, picture, etc) from a file as the treenode object. I can not seem to...
3
by: P K | last post by:
Hello, I have a dataset which is already loaded with data in one table. so dataset.tables("data") exists and has data. Now, I have to add another table to the dataset. The source for this...
0
by: paulnamroud | last post by:
Dear Sir, I have a problem while parsing my XML file. I can read all nodes except the one called "Color". I have a node called "Color" with an attribute "l" to determine the language is frensh...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.