加载到XElement时如何从文件中删除字符?\ [英] How to remove characters from a file while loading to XElement?\

查看:85
本文介绍了加载到XElement时如何从文件中删除字符?\的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我进行了适当的更改并将文件另存为.xml.

当我通过XElement打开文件时,它会向每个节点添加不需要的前缀,从而使

我无法通过IEnumerable遍历每个节点.

请帮助.

代码是:

Hi people,

I have made suitable changes and saved a file as .xml .

Wheni open the file by XElement , it adds unwanted precedings to each node , by which

im not able to loop through each node by IEnumerable.

Pls help.

The code is :

StreamReader stmReader = new StreamReader(flNameIs);
                String xsltData = stmReader.ReadToEnd();
                xsltData = xsltData.Replace("xsl:", "");
                xsltData="<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>"+xsltData;
                stmReader.Close();
                StreamWriter writer = new StreamWriter(tempFlName);
                writer.Write(xsltData);
                writer.Flush();
                writer.Close();
                XElement doc = XElement.Load(tempFlName);
            doc.RemoveAnnotations
               IEnumerable<XElement> e1 =from match in doc.Descendants("stylesheet").Descendants("template") select match;




在读取文件时,它将在每个节点起点添加文本"n1:".




While reading the file , it adds a text "n1: " to each node starting point.

Kindly help.

推荐答案

除非看到xml 文件的内容,否则很难找出问题中指定的添加n1:的原因. .但是,从问题描述中似乎可以看出,原因可能是由于在元素中添加了name space,在这方面,以下参考文献可能会有所帮助.
http://stackoverflow.com/questions/1231396/xelement-default- namespace-on-attributes-provides-unexpected-behaviour [ ^ ]
http://msdn.microsoft.com/en-us/library/bb387075.aspx [ ^ ]
http://stackoverflow.com/questions/1453564/how-to-addor-ignore-xml-namespace-when-using-xelement-load [
Unless the contents of the xml file are seen, it is difficult to figure out the cause for addition of n1: specified in the question. But, it appears from the question description that the reason may be due to the addition of name space to the element and in this regard the following references may be helpful.
http://stackoverflow.com/questions/1231396/xelement-default-namespace-on-attributes-provides-unexpected-behaviour[^]
http://msdn.microsoft.com/en-us/library/bb387075.aspx[^]
http://stackoverflow.com/questions/1453564/how-to-addor-ignore-xml-namespace-when-using-xelement-load[^]


这篇关于加载到XElement时如何从文件中删除字符?\的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆