Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Embed xml >Thread Next - Re: Embed xml Re: Embed xmlTo: NULL Date: 3/3/2006 2:15:00 PM
murali.trichy wrote:
> <span>
> <div align="center">
> < input id="myTxt" type="text"
> style="background-color:LightSteelBlue;width:90%" autosuggest="true" />
> <input type="button" value="myButton" onclick="myFunction();" />
> </div>
> </span>
>
> from the above sample xml I want to insert a table tag before and after
> input type=text tag.
The DOM does not work with tags, it works with nodes, you can create a
new table element node for instance, and insert that somewhere as a
children of another node. You can also create and insert new nodes as
children of the table element node. Or you can move existing nodes.
It is not clear what you want as the result but here is a simple example
in C#
string xmlMarkup = @"<span>
<div align=""center"">
<input id=""myTxt"" type=""text""
style=""background-color:LightSteelBlue;width:90%"" autosuggest=""true"" />
<input type=""button"" value=""myButton"" onclick=""myFunction();"" />
</div>
</span>";
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlMarkup);
XmlNode inputElement =
xmlDocument.SelectSingleNode(@"/span/div/input[@type = 'text']");
if (inputElement != null) {
XmlElement tableElement = xmlDocument.CreateElement("table");
XmlElement tbodyElement = xmlDocument.CreateElement("tbody");
tableElement.AppendChild(tbodyElement);
XmlElement trElement = xmlDocument.CreateElement("tr");
tbodyElement.AppendChild(trElement);
XmlElement tdElement = xmlDocument.CreateElement("td");
trElement.AppendChild(tdElement);
inputElement.ParentNode.InsertBefore(tableElement, inputElement);
tdElement.AppendChild(inputElement);
}
xmlDocument.Save(Console.Out);
The resulting serialized XML is then
<?xml version="1.0" encoding="utf-8"?>
<span>
<div align="center">
<table>
<tbody>
<tr>
<td>
<input id="myTxt" type="text"
style="background-color:LightSteelBlue;width:90%" autosuggest="true" />
</td>
</tr>
</tbody>
</table>
<input type="button" value="myButton" onclick="myFunction();" />
</div>
</span>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
