在这里,我们将给大家分享关于c#–使用PreserveWhitespaceLoadOptions在XDocument中添加带有新行的新XElements的知识,同时也会涉及到如何更有效地.NETXML
在这里,我们将给大家分享关于c# – 使用PreserveWhitespace LoadOptions在XDocument中添加带有新行的新XElements的知识,同时也会涉及到如何更有效地.NET XMLDocument.PreserveWhitespace:如何保留重要的空格?、CM: Create BAdI implementation for Webservice enabled word document、Document Builder: how does document element and variable cooperate、document.all还是document.getElementsByName的内容。
本文目录一览:- c# – 使用PreserveWhitespace LoadOptions在XDocument中添加带有新行的新XElements
- .NET XMLDocument.PreserveWhitespace:如何保留重要的空格?
- CM: Create BAdI implementation for Webservice enabled word document
- Document Builder: how does document element and variable cooperate
- document.all还是document.getElementsByName
c# – 使用PreserveWhitespace LoadOptions在XDocument中添加带有新行的新XElements
<root> <files> <file>a</file> <file>b</file> <file>c</file> <file>d</file> </files> </root>
所以我使用XDocument xDoc = XDocument.Load(path,LoadOptions.PreserveWhitespace)加载xml文档;
但是当我试图添加新元素xDoc.Root.Element(“files”)时.添加(new XElement(“test”,“test”));
xDoc.Root.Element(“files”).Add(new XElement(“test2”,“test2”));
它添加在同一行,因此输出如下:
<root> <files> <file>a</file> <file>b</file> <file>c</file> <file>d</file> <test>test</test><test2>test2</test2></files> </root>
那么如何在新行中添加新元素以节省初始格式?我尝试使用带有Setting.Indent = true的XmlWriter来保存XDocument,但正如我所见,当我使用xDoc.Root.Element()时,元素被添加到同一行.Add()
更新:程序加载,修改和保存文档的完整部分
using System; using System.Xml; using System.Xml.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { string path = @".\doc.xml"; XDocument xDoc = XDocument.Load(path,LoadOptions.PreserveWhitespace); //when i debug i see in "watch" that after these commands new elements are already added in same line xDoc.Descendants("files").First().Add(new XElement("test","test")); xDoc.Descendants("files").First().Add(new XElement("test2","test2")); XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; settings.Indent = true; settings.IndentChars = "\t"; using (XmlWriter writer = XmlTextWriter.Create(path,settings)) { xDoc.Save(writer); //Here i also tried save without writer - xDoc.Save(path) } } } }
解决方法
如果删除该选项,只需使用:
XDocument xDoc = XDocument.Load(path);
…然后适当地缩进.如果你想保留所有原始空格,但只是缩进新元素,我想你需要自己添加缩进.
.NET XMLDocument.PreserveWhitespace:如何保留重要的空格?
如何解决.NET XMLDocument.PreserveWhitespace:如何保留重要的空格??
简单来说,我有一个这样的 XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><root> <data> </data></root>
如你所见,根条目标签后有一个空格,数据标签中有一个空格。当我现在这样使用它时:
var xmldoc = new XmlDocument();
xmldoc.Load(stream);
...文档丢失了两个空格,根条目标签之后的一个和数据标签中的一个。
但是如果我这样使用它:
var xmldoc = new XmlDocument();
xmldoc.PreserveWhitespace = true;
xmldoc.Load(stream);
...然后保留两个空格。
但根据文档(documentation,备注部分),默认设置 PreserveWhitespace = false 应该保留重要的空格并去除不重要的空格。但它清除了所有这些,数据标签中的一个很重要。还是我理解错了?
解决方法
重要的空格是文本之间的空格,例如“这是一个示例”,但像您描述的空标签并不重要,将被 xml 解析器删除。
CM: Create BAdI implementation for Webservice enabled word document
Created by Jerry Wang, last modified on Oct 16, 2014
参考这篇document给product master 或者其他business transaction 创建word格式的attachment,并且这些word document能够支持web service:
我们可以将Genil model里支持web service的node上的field直接在word application里从右边的树状结构里拖拽到word左边的编辑区域:
当在UI上给product创建word attachment时,系统会自动call Genil Model PROD暴露出来的web service取得当前product instance的值并且赋给wrod document里对应的字段。系统提供了一个BAdI enhancement spot允许客户自定义:
BAdI的filter value设置成webservice的technical name:
可以利用该BAdI implementation 处理一些默认被Web service framework 过滤掉的属性为hidden的字段,如product的UPNAME:
本文同步分享在 博客“汪子熙”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
Document Builder: how does document element and variable cooperate
Created by Jerry Wang, last modified on Nov 03, 2014
In customizing, we can select one element and maintain a rule for it in order to achieve that the element would only appear in the final document once some condition meets. We could also maintain one or more variables to that element:
For example here we have assigned the variable "ZJERRY_TEST" to element ZCR_CD:
such variable has type CHAR10 and has default value "i042416".
In document template design time, we could drag the variable from right variable tree pane and drop them to the left word layout part:
In the document creation ui, we could input some data to the variable:
and in the runtime we could see the user input is merged to the final rendered document:
本文同步分享在 博客 “汪子熙”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与 “OSC 源创计划”,欢迎正在阅读的你也加入,一起分享。
document.all还是document.getElementsByName
if(oEle.length){}else{};
if(oEle.length){ for(var i = 0 ;i<oEle.length;i++){ oEle[i].value........ } } else{ oEle.value........ };
还好有document.getElementsByName()这个方法.它对一个和多个的处理是一样的,我们可以用:
oEle = document.getElementsByName(''aaa'')来引用
当oEle只有1个的时候,那么就是oEle[0],有多个的时候,用下标法oEle[i]循环获取,是不是很简单?
值得一提的是它对Name和ID的同样有效的.
但是它只能应用到document对象.相对应的,还有另一个方法,可以应用的对象会更广一点:
getElementsByTagName,比如我知道了一个
我要取div里面的所有input,这样写就可以了:aaa.getelementsbytagname(''input''),这样就有效的可以和别的div(比如说有个叫bbb的div,里面的也是一样的input)相区别.
同getelementsbytagname相对应,还有一个document.body.all.tags(),能用这个方法的对象比getelementsbytagname要小得多.但比getelementsbyname要多.
到这里我们还要提一下getelementbyid,它也是只有document对象才能使用,而且返回的是数组的第一个元素,呵呵,它的方法名都写明了是getelement而不是getelements,所以,千万不要搞浑了.
更多相关教程请访问 JavaScript视频教程
我们今天的关于c# – 使用PreserveWhitespace LoadOptions在XDocument中添加带有新行的新XElements的分享就到这里,谢谢您的阅读,如果想了解更多关于.NET XMLDocument.PreserveWhitespace:如何保留重要的空格?、CM: Create BAdI implementation for Webservice enabled word document、Document Builder: how does document element and variable cooperate、document.all还是document.getElementsByName的相关信息,可以在本站进行搜索。
本文标签: