473,569 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

embed xml

Hi,

I'm new to dotnet xml.

I want to embed my part of xml to existing xml data using xmldocument.
I think there is an option but i'm not getting exactly.

eg: DocumentElement .InsertAfter is used to insert the node but
reference is
problem ie how can i give ?

sample :

<span>
<div align="center">
< input id="myTxt" type="text"
style="backgrou nd-color:LightStee lBlue;width:90% " autosuggest="tr ue" />
<input type="button" value="myButton " onclick="myFunc tion();" />
</div>
</span>

from the above sample xml I want to insert a table tag before and after

input type=text tag.

Is possible ?
if yes pls suggest.

Thanks in advance.

Mar 3 '06 #1
8 1521
Hi Murali,

You can get the reference to the required "input" tag using a XPath
query. After that, just use the InsertBefore and InsertAfter functions
to insert away... !

The XPath to use here could be of the format :
".//span/div/input[@type='text']"
Try this :

=============== ===============

Dim xDoc As New XmlDocument()
xDoc.Load("MyFi le.xml")
Dim xList As XmlNode =
xDoc.SelectSing leNode(".//span/div/input[@type='text']")
Dim xNode, xParent As XmlNode
Dim xFrag As XmlDocumentFrag ment = xDoc.CreateDocu mentFragment()
Dim xFrag2 As XmlDocumentFrag ment = xDoc.CreateDocu mentFragment()
xFrag.InnerXml = "<TABLE id=""Table1"" cellspacing=""1 ""
cellpadding=""1 "" width=""100%"" border=""0"" />"
xFrag2.InnerXml = "<TABLE id=""Table2"" cellspacing=""1 ""
cellpadding=""1 "" width=""100%"" border=""0"" />"
xParent = xNode.ParentNod e
xParent.InsertB efore(xFrag, xNode)
xParent.InsertA fter(xFrag2, xNode)
xDoc.Save("MyFi le.xml"")

=============== ===============

You did not give a lengthier part of your XML file, so I thought it
would be easier to explain using an XmlNode. The XPath expression
should match multiple "input" nodes, one for every "Span/div". In that
case, you can use the SelectNodes("") method to get an XmlNodeList and
iterate through that List.

HTH,

Regards,

Cerebrus.

Mar 3 '06 #2
Perhaps use this as an alternative solution :
=============== =============== =============== =============== ===

Dim xdoc As New XmlDocument
xdoc.LoadXml("< span><div align='center'> <input id='myTxt'
type='text' style='backgrou nd-color:LightStee lBlue;width:90% '
autosuggest='tr ue'/><input type='button' value='myButton '
onclick='myFunc tion();' /> </div></span>")

Dim xmlOldEle As XmlElement =
xdoc.SelectSing leNode("//input[@type='text']")
Dim xmlNewEle As XmlElement = xdoc.CreateElem ent("table")
xmlNewEle.Appen dChild(xmlOldEl e)

xdoc.SelectSing leNode("//div").PrependCh ild(xmlNewEle)

=============== =============== =============== =============== ===
Cerebus,
Im not that hot on using XmlDocumentFrag ment, but would like to learn
more - any good resources on this?

Mar 3 '06 #3
wow,
really thanks guys I'm also solved - I'm basically C# programmer.

main function which I used here is : ReplaceChild() and AppendChild()
and other part of coding which I need to do.

& once again thanks to Cerebrus & dickster.

XmlElement newcatalogentry =
xmldoc.CreateEl ement("TABLE");
XmlAttribute tblwidthattr =
xmldoc.CreateAt tribute("width" );
tblwidthattr.Va lue = "100%";

newcatalogentry .SetAttributeNo de(tblwidthattr );
XmlAttribute tblcspaceattr =
xmldoc.CreateAt tribute("cellsp acing");
tblcspaceattr.V alue = "0";

newcatalogentry .SetAttributeNo de(tblcspaceatt r);
XmlAttribute tblcpadattr =
xmldoc.CreateAt tribute("cellpa dding");
tblcpadattr.Val ue = "0";

newcatalogentry .SetAttributeNo de(tblcpadattr) ;

XmlAttribute newcatalogattr =
xmldoc.CreateAt tribute("ID");
newcatalogattr. Value = "custctltbl2_1" ;

newcatalogentry .SetAttributeNo de(newcatalogat tr);
XmlElement firstelement =
xmldoc.CreateEl ement("TR");
newcatalogentry .AppendChild(fi rstelement);
XmlAttribute trtxtwidthattr =
xmldoc.CreateAt tribute("width" );
trtxtwidthattr. Value = "100%";

firstelement.Se tAttributeNode( trtxtwidthattr) ;
XmlElement tdxe =
xmldoc.CreateEl ement("TD");
XmlAttribute tdtxtwidthattr =
xmldoc.CreateAt tribute("width" );
tdtxtwidthattr. Value = "100%";
tdxe.SetAttribu teNode(tdtxtwid thattr);
firstelement.Ap pendChild(tdxe) ;
XmlNode xnode = xnod.Clone();
tdxe.AppendChil d(xnode);
XmlElement lstelmt =
xmldoc.CreateEl ement("SELECT") ;
XmlAttribute sltwidthattr =
xmldoc.CreateAt tribute("style" );
sltwidthattr.Va lue = "width:91%" ;
lstelmt.SetAttr ibuteNode(sltwi dthattr);

XmlAttribute selidattr =
xmldoc.CreateAt tribute("ID");
selidattr.Value = "custsugg" + id;
lstelmt.SetAttr ibuteNode(selid attr);
XmlAttribute selclsattr =
xmldoc.CreateAt tribute("classn ame");
selclsattr.Valu e = "drp";
lstelmt.SetAttr ibuteNode(selcl sattr);
XmlAttribute selsizeattr =
xmldoc.CreateAt tribute("size") ;
selsizeattr.Val ue = "4";
lstelmt.SetAttr ibuteNode(selsi zeattr);
XmlElement tdlstelmt =
xmldoc.CreateEl ement("TD");
XmlAttribute tdsltwidthattr =
xmldoc.CreateAt tribute("width" );
tdsltwidthattr. Value = "100%";
tdlstelmt.SetAt tributeNode(tds ltwidthattr);
tdlstelmt.Appen dChild(lstelmt) ;

XmlElement trlstelmt =
xmldoc.CreateEl ement("TR");
XmlAttribute tridattr =
xmldoc.CreateAt tribute("ID");
tridattr.Value = "custsugg" + id;
trlstelmt.SetAt tributeNode(tri dattr);

XmlAttribute trsltwidthattr =
xmldoc.CreateAt tribute("width" );
trsltwidthattr. Value = "100%";
trlstelmt.SetAt tributeNode(trs ltwidthattr);
XmlAttribute trposatt =
xmldoc.CreateAt tribute("style" );
trposatt.Value =
"position:absol ute;display:non e;visibility:hi dden";
trlstelmt.SetAt tributeNode(trp osatt);
trlstelmt.Appen dChild(tdlstelm t);
newcatalogentry .AppendChild(tr lstelmt);

divnod.ReplaceC hild(newcatalog entry, xnod);

Mar 3 '06 #4
Hi Murali,

I personally find it much more concise and efficient to simply load an
XML string (where it is not known beforehand), and then make inserts /
removals from the Main document, rather than adding elements and
attributes individually. It also uses far less variables and there is
less room for confusion. You might experiment with both methods.

Dickster,

Your solution will surely do the job, but it might be more complicated
to add attributes to the "table" element.
Im not that hot on using XmlDocumentFrag ment, but would like to learn
more - any good resources on this?


Well, using an XmlDocumentFrag ment is pretty simple. (Note: I'm talking
about VS 2003)
1. Instantiate it using the CreateDocumentF ragment() method of the
XmlDocument
2. Set it's InnerXml property to the XML markup of the fragment you
want to insert / replace etc.
3. Use it wherever you can use an XmlNode, since it inherits from
XmlNode.

As for resources, I just use the MSDN help. You might search online for
some good tutorials.

HTH,

Regards,

Cerebrus.

Mar 3 '06 #5
Thanks Cerebus

XmlNode is abstract - XmlDocument, XmlElement & XmlDocumentFrag ment
all inherit from it. Which is fine

What I can not get my head round is that XmlElement objects have to
come from a XmlDocument Context..

Consider this code:
----------------------------------------------------------
Dim xdoc As New XmlDocument
xdoc.LoadXml("< table></table>")
Dim xmlEle As XmlElement = xdoc.CreateElem ent("tr")

But I cant then say:

xmlNewEle.Appen dChild(<< A New XmlElement object which would be a 'td'
)


Any thoughts?

Mar 3 '06 #6
> load an
XML string (where it is not known beforehand), and then make inserts /
removals from the Main document, rather than adding elements and
attributes individually


Hi Cerebrus,

Can you expain with sample code, then it is clear for me.

bye
murali@pune

Mar 4 '06 #7
Hi Murali,

The sample code is there in my reply to your original post. Did you try
it ?

Regards,

Cerebrus.

Mar 4 '06 #8
The XmlDocument type has a method

..LoadXml()

You can either load an xml file by passing in the path

..LoadXml("path to xml file")

or XML as a string

..LoadXml("<tab le></table>")

Mar 6 '06 #9

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

Similar topics

0
3105
by: Wolfgang Schwanke | last post by:
Dear usenet, I'm having the following small problem. I've been ask to add some Quicktime panoramas to a website. The author of the panoramas has made two versions of each: One in MOV format, which needs a Quicktime plugin, and one Java applet. He's also kindly supplied me with sample HTML code for each. The code looks like this...
3
5208
by: Tony Sutton | last post by:
I have this following code in my html file: <object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab# version=7,0,0,0" width="320" height="320"> <param name="src" value="file.dcr" /> <embed src="file.dcr"...
11
4470
by: Anna | last post by:
Hi all. I want to embed the EMBED tag in the object tag. I understood that I need to provide a PARAM tag inside the OBJECT whose value will hold the content of EMBED src attribute, but after that I've got confused. For example, what should be put into classid and codebase attributes of the OBJECT now embedding the EMBED tag?
2
5415
by: François de Dardel | last post by:
Please don't scream that EMBED is evil ! What I am doing is <EMBED SRC="BWV659.mid" AUTOSTART="false" LOOP="TRUE" CONTROLS="SMALLCONSOLE" WIDTH="50" HEIGHT="15" TITLE="BWV 659"> Note the AUTOSTART="false"... In the good old days of Netscape 3 or so, just <A HREF="BWV659.mid">Musique</A> would open a small console in the active page...
2
3089
by: Cris Curtis | last post by:
When I use an embed tag that uses a dynamic aspx page, the dynamic aspx page appears to get called 2 times instead. Below is code that adds an embed tag to a placeholder control that will use a second aspx page to generate the svg for the embed. svgchart.Controls.Clear(); string strSRC =...
8
3072
by: Cowan Services | last post by:
My apologies if this has been covered before, but I was unable to download messages before 11/23/05. I am trying to bring some HTML pages w/embedded .WMV files into W3C compliance. Right now, they use the <embed> tag and are therefore not compliant. I've found a couple of work arounds for Flash files, but none for ..WMV files. The client...
1
2972
by: Andrew Poulos | last post by:
With "normal" SWF HTML there's an EMBED tag nested within an OBJECT tag. How can I check which tag is actually displaying the SWF? I'm using CSS on them and the style on the OBJECT affects the EMBED tag so I'm going to use some code to correct it but I can't tell which tag is responsible for the display. Andrew Poulos
6
2371
by: qualitychecker | last post by:
Hello thanks for your help.. I try to reference a PHP module from within a HTML file, see below ---------------------------------------- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"> <head> <titleMy title </title> </head> <body> on place un embed <embed id="embed1" alt="ne marche pas..." src="ws.php?
2
8056
dream party
by: dream party | last post by:
Inserting a Flash (SWF, FLV) file into HTML web page is already an old and familiar thing to all of us. It is a rather non-flexible thing that just to edit some options in the template. However, I did not understand some parameters totally in the HTML tag. These days when I was surfing the Internet I have found some comprehensive introduction to...
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.