开发者

Linq To XML: Writing xsi into an element?

开发者 https://www.devze.com 2023-02-13 16:02 出处:网络
Just playing about with LinqToXml and I need to form a xelement as follows: Dim xe As XElement = _ <Xml>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消