Linq To XML: Writing xsi into an element?
Just playing about with LinqToXml and I need to form a xelement as follows:
Dim xe As XElement = _
<Xml>
<ElementOne>
<SubElement></SubElement>
<SubElement></SubElement>
</ElementOne>
<ElementWithXsi xsi:type="XsiForElementWith">
<SubElement></SubElement>
</ElementWithXsi>
</Xml>
This creates an error here: xsi:type "XML namespace prefix 'xsi' is not defined"
Is it p开发者_Python百科ossible to write this in Linq to xml?
Well with XML and namespaces any prefix besides the "xml" and the "xmlns" prefixes needs to be defined so you need xmlns:xsi="someURI"
(probably xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
but that is a guess, I don't know which namespace you want) in your XML document or, as long as you use VB.NET's XML literals you can use Imports <xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
in program's Imports section.
精彩评论