0

スペース名を追加するときに xml 文字列を生成できません。これは、私のxmlを次のように生成したい方法です

xml サンプル:

<Feedback xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Record>
        <ID>2FAC636E-F96C-4465-9272-760BAF73C0DF</QRCodeID>
        <SubID>10B5236C-47FD-468D-B88D-D789CA0C663A</SubmissionID>
        <UserID>1</UserID>
        <Page>1</Page>
    </Record>
    <Record>
        <ID>219C462B-B874-4408-AFBA-CA727922D50F</QRCodeID>
        <SubID>10B5236C-47FD-468D-B88D-D789CA0C663A</SubmissionID>
        <UserID>1</UserID>
        <Page>2</Page>
    </Record>
</Feedback>

私のコードは今どのように見えるか:

XDocument xdoc = new XDocument(
            new XElement("Feedback xmlns:i='http://www.w3.org/2001/XMLSchema-instance'",
                new XElement("Record",
                    new XElement("ID", idGuid),
                    new XElement("SubID", subGuid),
                    new XElement("UserID", 2),
                    new XElement("Page", pages)
                    )
            )
        );

実行すると"Feedback xmlns:i='http://www.w3.org/2001/XMLSchema-instance'"、文字「 」が気に入らないというエラーがスローされます

4

3 に答える 3

0

この MSDN ページを見てください。知っておくべきことはすべて説明されています

于 2013-07-02T17:56:21.840 に答える
0

Namespacesを使用する必要があると確信しています。

これは、無効な文字列全体でマークアップを作成しようとしています。

于 2013-07-02T17:56:32.237 に答える
0

ドキュメント hereは、次のようなものが機能することを示唆しています。

XDocument xdoc = new XDocument(
    new XElement("Feedback",
        new XAttribute(XNamespace.Xmlns + "i", "http://www.w3.org/2001/XMLSchema-instance"),
        new XAttribute(XNamespace.Xmlns + "j", "http://schemas.sitename.com/2013/03/Project.Models"),
        new XElement("Record",
            new XElement("ID", idGuid),
            new XElement("SubID", subGuid),
            new XElement("UserID", 2),
            new XElement("Page", pages)
        )
    )
);
于 2013-07-02T17:56:40.057 に答える