Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Embed xml

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent