Two Deep XML?

This is a multi-part message in MIME format.

------=_NextPart_000_0006_01C5D3EC.718FA8B0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I have some code which creates an XML output like this:

<  Product>

       <Product ID>1</ProductID

       <ProductValue>5.00</ProductVaue>

</Product>

<  Product>

       <Product ID>2</ProductID

       <ProductValue>10.00</ProductVaue>

</Product>

Here it is:

newElem =3D doc.CreateElement("Product");



    childElem =3D doc.CreateElement("ProductID");

   childElem.AppendChild(doc.CreateTextNode(ProductID.ToString()));

   newElem.AppendChild(childElem);

   childElem =3D doc.CreateElement("ProductName");

   childElem.AppendChild(doc.CreateTextNode(productname));

   newElem.AppendChild(childElem);

I now want to add one more level of depth to my XML so that the output =
is like this (new stuff in bold):

<  Product>

       <Product ID>1</ProductID

       <ProductValue>5.00</ProductVaue>

      <Discount>

            <QtyLow>1</QtyLow><QtyHigh>5</QtyHigh><Value>5%</Value>

       </Discount>

      <Discount>

            <QtyLow>6</QtyLow><QtyHigh>10</QtyHigh><Value>10%</Value>

       </Discount>

</Product>

But I'm drawing a blank as how to code this.  Can anyone steer me in the =
right direction?





------=_NextPart_000_0006_01C5D3EC.718FA8B0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2722" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV>
<P><FONT face=3DArial size=3D2>I have some code which creates an XML =
output like=20
this:</FONT></P>
<P><FONT face=3DArial size=3D2>&lt;&nbsp;&nbsp;Product&gt;</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;Product=20
ID&gt;1&lt;/ProductID</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;ProductValue&gt;5.00&lt;/ProductVaue&gt;</FONT></P>
<P><FONT face=3DArial size=3D2>&lt;/Product&gt;</FONT></P>
<P><FONT face=3DArial size=3D2>&lt;&nbsp;&nbsp;Product&gt;</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;Product=20
ID&gt;2&lt;/ProductID</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;ProductValue&gt;10.00&lt;/ProductVaue&gt;</FONT></P>
<P><FONT face=3DArial size=3D2>&lt;/Product&gt;</FONT></P>
<P><FONT face=3DArial size=3D2>Here it is:</FONT></P>
<P><FONT face=3DArial size=3D2>newElem =3D =
doc.CreateElement("Product");</FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2></FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; childElem =3D=20
doc.CreateElement("ProductID");</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;=20
childElem.AppendChild(doc.CreateTextNode(ProductID.ToString()));</FONT></=
P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;=20
newElem.AppendChild(childElem);</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp; childElem =3D=20
doc.CreateElement("ProductName");</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;=20
childElem.AppendChild(doc.CreateTextNode(productname));</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;=20
newElem.AppendChild(childElem);</FONT></P>
<P><FONT face=3DArial size=3D2>I now want to add one more level of depth =
to my XML=20
so that the output is like this (new stuff in bold):</FONT></P>
<P><FONT face=3DArial size=3D2>&lt;&nbsp;&nbsp;Product&gt;</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;Product=20
ID&gt;1&lt;/ProductID</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;ProductValue&gt;5.00&lt;/ProductVaue&gt;</FONT></P>
<P><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<STRONG>=20
&lt;Discount&gt;</STRONG></FONT></P>
<P><FONT face=3DArial=20
size=3D2><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
&lt;QtyLow&gt;1&lt;/QtyLow&gt;&lt;QtyHigh&gt;5&lt;/QtyHigh&gt;&lt;Value&g=
t;5%&lt;/Value&gt;</STRONG></FONT></P>
<P><FONT face=3DArial=20
size=3D2><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Discount&=
gt;</STRONG></FONT></P>
<P><FONT face=3DArial size=3D2><STRONG>&nbsp;&nbsp;&nbsp; &nbsp;=20
&lt;Discount&gt;</STRONG></FONT></P>
<P><FONT face=3DArial=20
size=3D2><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
&lt;QtyLow&gt;6&lt;/QtyLow&gt;&lt;QtyHigh&gt;10&lt;/QtyHigh&gt;&lt;Value&=
gt;10%&lt;/Value&gt;</STRONG></FONT></P>
<P><FONT face=3DArial=20
size=3D2><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Discount&=
gt;</STRONG></FONT></P>
<P><FONT face=3DArial size=3D2>&lt;/Product&gt;</FONT></P>
<P><FONT face=3DArial size=3D2>But I'm drawing a blank as how to code =
this.&nbsp;=20
Can anyone steer me in the right direction?</FONT></P>
<P><FONT face=3DArial size=3D2></FONT>&nbsp;</P>
<P><FONT face=3DArial size=3D2></FONT>&nbsp;</P></DIV></BODY></HTML>

------=_NextPart_000_0006_01C5D3EC.718FA8B0--

0
harry7872 (4)
10/18/2005 9:01:32 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
620 Views

Similar Articles

[PageSpeed] 9

Hello!


> But I'm drawing a blank as how to code this.  Can anyone steer me in the 
> right direction?

XmlDocument doc = new XmlDocument();
   XmlElement product = doc.CreateElement("Product");
     XmlElement discount = doc.CreateElement("Discount");
       XmlElement qtylow = doc.CreateElement("QtyLow");
       qtylow.AppendChild( doc.CreateTextNode("1") );
     discount.AppendChild(qtylow);
   product.AppendChild(discount);
doc.AppendChild(product);


All Elements, regardless where they are added into the tree are created 
using the XmlDocument.CreateXXX-Methods. You can then add the nodes you 
created like this to any other XmlElement created from the same XmlDocument.
It does not matter if you use doc.AppendChild(product) before or after 
adding the child-Elements of <product />, the code could also look like 
this:

XmlDocument doc = new XmlDocument();
   XmlElement product = doc.CreateElement("Product");
   doc.AppendChild(product);
     XmlElement discount = doc.CreateElement("Discount");
     product.AppendChild(discount);
       XmlElement qtylow = doc.CreateElement("QtyLow");
       discount.AppendChild(qtylow);
         qtylow.AppendChild( doc.CreateTextNode("1") );


-- 
Pascal Schmitt
0
10/18/2005 9:40:02 PM
Thanks Pascal!  It's easy to see now!!

Best
Harry

"Pascal Schmitt" <newsgroup@cebra.nu> wrote in message 
news:u5z0$xC1FHA.2312@TK2MSFTNGP14.phx.gbl...
> Hello!
>
>
>> But I'm drawing a blank as how to code this.  Can anyone steer me in the 
>> right direction?
>
> XmlDocument doc = new XmlDocument();
>   XmlElement product = doc.CreateElement("Product");
>     XmlElement discount = doc.CreateElement("Discount");
>       XmlElement qtylow = doc.CreateElement("QtyLow");
>       qtylow.AppendChild( doc.CreateTextNode("1") );
>     discount.AppendChild(qtylow);
>   product.AppendChild(discount);
> doc.AppendChild(product);
>
>
> All Elements, regardless where they are added into the tree are created 
> using the XmlDocument.CreateXXX-Methods. You can then add the nodes you 
> created like this to any other XmlElement created from the same 
> XmlDocument.
> It does not matter if you use doc.AppendChild(product) before or after 
> adding the child-Elements of <product />, the code could also look like 
> this:
>
> XmlDocument doc = new XmlDocument();
>   XmlElement product = doc.CreateElement("Product");
>   doc.AppendChild(product);
>     XmlElement discount = doc.CreateElement("Discount");
>     product.AppendChild(discount);
>       XmlElement qtylow = doc.CreateElement("QtyLow");
>       discount.AppendChild(qtylow);
>         qtylow.AppendChild( doc.CreateTextNode("1") );
>
>
> -- 
> Pascal Schmitt 


0
harry7872 (4)
10/18/2005 10:11:08 PM
Reply:

Similar Artilces:

synchiing two computers?
Is there a way to synch Outlook on two computers? I end up with some email on my laptop and some on my desktop - it would be nice if the two could be synched so that I could have all of my email on both computers. Take a look here, it may help: http://www.slipstick.com/outlook/sync.htm -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. After furious head scratching, Bill Andersen asked: | Is there a way to synch Outlook on two computers? | I end up with some...

Compare two cells in two different files and return answer
I am attempting to compare two text cells and if they both exist, I want to bring in a "yes" answer. If they don't, bring in a "no" answer. Here's an example of text. File 1 Col A Col B BRATTA ZPB_COMMON AHERNC ZPB_COMMON GENCABH ZPB_COMMON File 2 Col A Col B BRATTA ZPB_COMMON AHERNC ZPB_COMMON GENCABH So, what I want to do is say in File 1 take cells A1 and B1 compare them to File 2 and search Col A and Col B and if there is an exact mat...

Pivot table for two different data variables
I have the following table Name type Cost overhead amy C1 23 12 bob C2 129 17 cat C2 36 45 doo C2 100 32 I owuld like to create a pivot table that looks similar to: the standard pivot table. (Please ignore type for now.) name Data Total amy Sum of overhead 200 Sum of cost 12 bob Sum of overhead 130 Sum of cost 23 cat Sum of overhead 90 Sum of cost 19 doo Sum of overhead 87 Sum of cost 34 Total Sum of overhead 507 Total Sum of cost 88 But with overall total (overhead + cost) for ...

XML Element mapping
How can I map more than one element to a single cell? Specifically-Zip+4 is 2 elements. I want both elements in one cell. -- KF-RIDOT ...

COUNTIF (?) on two criteria
I have a spreadsheet that logs work activities and records team members' completion of project units. Column B records team member names. Column C has project unit status - 'pending', 'beta' or 'completed'. It's easy to set up a formula to count how many units are allocated to each team member - =COUNTIF(B1:B1000,"Joe"). But what I need to do is set up formulas to count how many units Joe has completed, or has pending or at beta, and this means assessing data in both columns - which COUNTIF won't do. This doesn't strike me as an especially...

Two IF Statements with two answers
In cell J9 I need a formula that would do the following: If G9="Yes" then F9, If G9="No" then -f9 Note: G9 has a drop down list with Yes, No answers. If there are no other alternatives that yes and no =IF(G9="Yes",F9,-F9) otherwise =IF(G9="Yes",F9,IF(G9="No",-F9,"") Regards, Peo Sjoblom "heater" wrote: > In cell J9 I need a formula that would do the following: > > If G9="Yes" then F9, If G9="No" then -f9 > > Note: G9 has a drop down list with Yes, No answers. > =IF(G9=&qu...

Two axis
Positioning the Vertical axes: I have a chart where there are two axes. The first implementation produced the two scales on the right side, one inside, the other outside the chart area. Unusual, but luckily it fits well the chart. I tried to duplicate the feat with another dataset (similar in structure) and did not even get the second scale to show right, left or center (data plotted with two different scales allright). Where is the info to control these functionalities? Tx, Pierre On Wed, 29 Oct 2003 17:48:13 +0100, pl.carry <pl.carry@wanadoo.fr> wrote= : > Positioning the Vertic...

TreeView XML Question
Hi Guys, I have different pages in ASP.NET.And i have a treeview that populates XML that i use as the MENU. Is it possible to have one asp.net page but populating different XML to the mENU? Any ideas? ...

plot two groups of numbers on one series of xy coordinates.
how to create a plot from separate x and y values. i.e. y values do not correspond to the same set of x values. example x1= 5, y1=10; x2= 8, y2=15 I can read your question 2 ways; A) you data looks like this x y 5 10 8 15 etc. Select the data and make an XY chart B) you have two sets of data x1 y1 5 10 10 12 17 15 21 20 and x2 y2 3 8 7 14 12 19 18 24 Make an XY chart of the first data series Select all the data (including headers) for second set, and use Copy Click the chart to activate it Use Edit | Paste Special .... indicate New Ser...

two variables
I have a query that asks for collcode, collcode2 and booth. On any given day an employee may be collcode or collcode2. I would like to know how many times a certain emp has been paired with another employee. So how do I ask if an employee has been collcode/collcode2 and who the other person was? I hope this question makes sense. Thanks for any help Query one: SELECT CollCode, CollCode2, Booth FROM YourTable UNION ALL SELECT CollCode2, CollCode, Booth FROM YourTable Query Two SELECT CollCode, CollCode2, Count(CollCode) AS TIMESPAIRED FROM QueryOne GROUP BY CollCode, CollCode2 IF y...

how to transform escaped xml contents in xmlnode
Hi, I have an XML document, created from ADO DataSet, which contains XML data in some nodes shown below: <NewDataSet> <Table> <field_name>My Selection</field_name> <field_type>dropdown</field_type> <field_choice_text> &lt;Choices&gt;&lt;Choice choice_text=\"xxx\" /&gt;&lt;Choice choice_text=\"yyy\" /&gt;&lt;Choice choice_text=\"zzz\" /&gt;&lt;/Choices&gt; </field_choice_text> <field_answer> xxx </field_answer> </Table> </NewDataSet> How can I get ...

Find two PCI instance but load Init() one time
Hi all, I'm developing a stream interface driver for my PCI device under WinCE 6.0 and this driver works very well currently. Now, I got a problem when testing two the same PCI devices with my stream driver. The registry can find two PCI instances (i.e. PCI\Instance\mydrv1, PCI\ Instance\mydrv2) but system only call my XXX_init() one time. Does anyone know what the problem is? The following information is my registry setting: ================================================================== [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\PCI\Template\mydrv] "Dll"="myd...

Comparing two lists for matches
Hi, I am trying to do the following: There are two sets of supplier lists - A List and B List. I need to compare the two lists. Source A is my master. Source B is a subset of that but has contact information for all the suppliers. Hence, my goal is to retrieve the contact information from Source B and match it to the suppliers of Source A. The above can be easliy achieved using a vlookup funtion. But the problem is that some of the supplier names in the two lists are not exact matches. Hence, vlookup does not catch it. For instance, a supplier is listed as ABC Inc. in A list and as ABC, inc....

Shell Game with XML Attributes
I have a problem that I suspect shouldn't be this hard to figure out, but I'm a .NET newbie so I'm looking for help. I am reading from an XML file to populate a combo box with the value of an "Name" attribute to several elements. When the user selects an item from the combo and clicks a command button, my application needs to: 1. Find the parent element of the "Name" attribute 2. Find the value of the "ID" attribute of the same element 3. Write the value of the ID attribute to another XML file. I can do everything except steps 1 and 2 ;) I've in...

Compare two lists of names
Can you compare two lists of names where one list is last name first and the other is first name last? try this formual: =RIGHT(TRIM(E2),LEN(E2)-FIND(" ",E2))&" "&TRIM(LEFT(TRIM(E2),FIND(" ",E2))) it will convert First name last name to last name, first name or Visa versa. then you can compare your lists. "ea" wrote: > Can you compare two lists of names where one list is last name first and the > other is first name last? ...

Two copies of all Mailboxes
Using my sbs2003 srver with exchange 2003 installed - I notice two copies of all users mail box in the list of mailboxes using outlook 2003 on the same server. When I try to close these I get an error syaing mail boxes in use. I cn not remove them. Can you tell me how to remove these so I have just on mail box visible per user? thx Kevin Cain Class TECHNOLOGY ...

How do I create a chart on two axes with two lines and a bar
I am trying to compare two final stock prices to the average volume. So, teh left axes would have the numbers for the stock prices, and the right axes would have the volume. The two stock prices would be lines using the left, and the volume a bar using the right. I can do one line and one bar, but I can't figure out two lines. Can anyone help? Forget the built in custom types. It's better to build your own. Create your chart using all the data, to produce a chart with three line series all on the primary axis. Select the Volume series, and on the Chart menu, use Chart Type to ch...

how do I display last two digits of a SSN in a separate column
I am trying to create a formula to take an existing list of 8 or 9 digit numbers and display the last two numbers in a separate column. Is this possible? Try =RIGHT(A1,2) -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "katbone1" wrote: > I am trying to create a formula to take an existing list of 8 or 9 digit > numbers and display the last two numbers in a separate column. Is this > possible? Hi Use a formula =3Dright(A1, 2...

Combining Text and numbers from two cells
Hi all please help i have a cell with a number such as 6000 (a1) and another cell with a text aaa- and i would like to combine them in another cell to make aaa-6000, could somebody please help me with a formula? thanks Andrew -- koba ------------------------------------------------------------------------ koba's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=28639 View this thread: http://www.excelforum.com/showthread.php?threadid=492631 Hi! Try this: A1 = 6000 B1 = aaa =B1&"-"&A1 Biff "koba" <koba.1zwtbm_1134361504.8695...

Working with two Word Documents in Windowjs 7
I'm struggling to adjust to Windows 7 from XP. How do I reduce the size of two Word documents so I can view them "side by side" so to speak. The button that reduces the size of a document shrinks it to a tiny inch or so icon square in the corner of the screen. Is there no choice to view the entire document, reduced in size, when another document is on-screen? Many thanks! When you "restore" a window, it can be resized by dragging the sides. Or you can use the "snap" feature in Windows 7 to arrange windows; see http://windows.microsoft.com/en...

possible to chart two sets of data (4 columns) with common X & Y axes?
Is there a way to combine two sets of data with common X & Y axes on a scatter chart that lets the viewer see that there are two clusters of data (say with different point types or colors)? Here's an example: Column 1: Test session Column 2: Distance traveled under condition 1 Column 3: Travel time under condition 1 Column 4: Distance traveled under condition 2 Column 5: Travel time under condition 2 Columns 2/4 and 3/5 are the Y & X axes respectively. I want to overlay the raw data so that the clusters that emerge from condition 1 and 2 are easily seen (different colored dots fo...

Multiplying two columns
How do I multiply column A (length) by column B (width)? All I want is a new column C (area) where the cells correspond to what I just multiplied if one were to look from left to right. A x B = C. I can do it for two numbers but not whole columns.... In (eg) C1 =A1*B1 Select C1 Point to bottom right corner until you see the plus Double click To get the sum of all A*B you can use: =SUMPRODUCT(A1:A50,B1:B50) -- Regards Norman Harker MVP (Excel) Sydney, Australia njharker@optusnet.com.au Excel and Word Function Lists (Classifications, Syntax and Arguments) available free to good homes. ...

How do I print two worksheets as a two-sided document?
I am trying to print two separate worksheets from a workbook as a two-sided document. Is this possible? If so, how? Using Excel 2003. If your printer is not capable of two sided printing then I think you have to print one worksheet, flip the paper and put it back in the printer, and print the other worksheet. Brilliant, no?<g> -- Jim Rech Excel MVP "Col Flagg" <Col Flagg@discussions.microsoft.com> wrote in message news:A1298BBB-8CD8-4A0E-A49C-F71C6B28CC69@microsoft.com... |I am trying to print two separate worksheets from a workbook as a two-sided | document. Is t...

update two tables with one form
Hi, I am creating a new database and ideally would like one form only to enter the relevant data, but that means it has to update two or more tables from that. Is that possible? Thanks Christina Yes, but you need to explain your data structure a bit. In a relational database, you can have several different types of relationships. What does your form do? If you have a form that adds customers, then it would probably just update one table. If you then want to add products to your database, that would probably be a separate form. Now, when it comes time to sell a product, you would...

HELP ! Update or Create New XML File
Hi, I'm working on the .NET Compact Framework, and I need a way in which i store products in an xml file. Basically, when i add a product to the system, i want to either add it to the XML file, (if it exists), or create a new XML file with the item in it if the file doesn't exist. Bearing in mind I'm on the compact framework, does anyone have any suggestions how i can check the file ? Many thanks. This is my code so far. using System; using System.Xml; using System.IO; using System.Text; namespace SaveExample { /// <summary> /// Summary description for save. /// ...