我是使用C#处理XML文档的新手。
我的C#代码:
XmlNode root = xmlDoc.DocumentElement;
XmlElement childNode = xmlDoc.CreateElement("link:schemaRef");
root.AppendChild(childNode);
XmlAttribute type = xmlDoc.CreateAttribute("xlink:type");
type.Value = "simple";
childNode.Attributes.Append(type);
XmlAttribute type2 = xmlDoc.CreateAttribute("xlink:href");
type2.Value = "http://taxonomi.xbrl.se/se/fr/sme/rbf/2008-09-30/se-sme-rbf-2008-09-30.xsd";
childNode.Attributes.Append(type2);但是,使用该代码将生成这样的XML:
<schemaRef type="simple" href="http://taxonomi.xbrl.se/se/fr/sme/rbf/2008-09-30/se-sme-rbf-2008-09-30.xsd" />但是,我希望生成的XML元素如下所示:
<link:schemaRef xlink:type="simple" xlink:href="http://taxonomi.xbrl.se/se/fr/sme/rbf/2008-09-30/se-sme-rbf-2008-09-30.xsd" />我想我已经找到了我的问题的解决方案,下面是我的C#代码,作为我的临时解决方案:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"" + dir + "" + filename);
XmlNode root = xmlDoc.DocumentElement;
//##Insert XBRL link scheme
var schemaRefElement = xmlDoc.CreateElement("link", "schemaRef", "urn:linkbase");
schemaRefElement.SetAttribute("type", "http://www.w3.org/1999/xlink", "simple");
schemaRefElement.SetAttribute("href", "http://www.w3.org/1999/xlink","http://www.bi.go.id/xbrl/2012-06 18/view/Pelaporan%20Keuangan/Rincian%20aset%20non%20finansial/" + reportname + "/" + reportname + ".xsd");
root.AppendChild(schemaRefElement);
xmlDoc.Save(@"" + dir + "" + filename);但我仍然在寻找其他最好的解决方案;实际上,我更喜欢使用LINQ。
发布于 2014-03-06 14:59:24
试试这个;
XmlDocument doc = new XmlDocument();
var mmd = doc.CreateElement("mmd");
var element = doc.CreateElement("link", "schemaRef", "http://www.xbrl.org/2003/linkbase");
mmd.AppendChild(element);
XmlAttribute xmlAttribute = doc.CreateAttribute("xlink", "type", "http://www.w3.org/1999/xlink");
xmlAttribute.Value = "simple";
element.Attributes.Append(xmlAttribute);
xmlAttribute = doc.CreateAttribute("xlink", "href", "http://www.w3.org/1999/xlink");
xmlAttribute.Value = "http://taxonomi.xbrl.se/se/fr/sme/rbf/2008-09-30/se-sme-rbf-2008-09-30.xsd";
element.Attributes.Append(xmlAttribute);https://stackoverflow.com/questions/14670122
复制相似问题