私は、まさにこのようなXML文書を抽出することができました上記のコードでは、このWebサービスメソッドはXSIを追加:私のXML文書へのタイプ
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XAttribute attribute = new XAttribute(xsi + "type", "xsd:string");
XElement node_user_id = new XElement("user_id", attribute, user.code);
XDocument doc = new XDocument(new XElement("ranzcp_user", new XAttribute(XNamespace.Xmlns + "ns1", "urn:logon"), node_user_id));
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(elem.ToString());
を使用してXMLドキュメントタイプを抽出するためのコードがあります
を<ranzcp_user xmlns:ns1="urn:logon">
<user_id xmlns:p3="http://www.w3.org/2001/XMLSchema-instance" p3:type="xsd:string">12345678</user_id>
</ranzcp_user>
しかし、私が本当に持っている必要があることはこれです:
<ranzcp_user xmlns:ns1="urn:logon">
<user_id xsi:type="xsd:string">12345678</user_id>
</ranzcp_user>
は私がFを必要とするフォーマットを得ることができる方法はありますxmlを解析した後、xsi:type = "xsd:string"属性が必要でしたか?
TIA!
なぜ名前空間を削除しますか?エラーが出ていますか?誰がXMLを生成していますか?スキーマを使用する名前空間でエラーが発生した場合、xmlは無効であり、修正する必要があります。名前空間を削除することは難しいことです。 – jdweng
@under_score 'xsi:prefix 'の宣言をしない' xsi:type'( 'xmlns:xsi =" ... "')は、XML仕様に準拠していないものになります。標準のXMLパーサーでは生成/処理できません) – har07
@ har07と同意します。詳細については、「XSDでxsi:typeを使用してXML要素の値を制限する方法」(http://stackoverflow.com/questions/33808790/how-to-restrict-the-value-of-an- xml-element-using-xsitype-in-xsd) – kjhughes