Reputation: 35054
I have a XML content
<p>
This is my <em>Styled</em> content.
</p>
What I need to do is check the string
This is my <em>Styled</em> content.
exits on the DOM. How do i do this? I tried using XPath text() but that strips out the <em>
. Any pointers to this?
Upvotes: 0
Views: 217
Reputation: 167726
Well you have to understand that the DOM is a tree model of nodes and does not contain any marked up elements or tags you are looking for, in your sample there is a p
element node contaning several child nodes, a text node, an em
element node, and a further text node. Depending on the DOM implementation there might be properties or methods exposed on nodes to serialize them back to markup, for instance the DOM API in the .NET framework has properties http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.innerxml.aspx so there you could check e.g. p.InnerXml.Contains("This is my <em>Styled</em> content.")
. Within browsers there is support for the innerHTML property so with Javascript inside browsers you could check that property in a similar way.
Upvotes: 1