!!!!!!!!!! 怎样将Text文件导出为XML文件呢,

约修亚 2007-07-14 05:43:20
我有几个Text 文件如下:

TO: Chris Koscinski / flCfl CLO 2007-1 LTD FROM: JPMC Agent Plus

DATE: ThU Apr 12 2007 14:58 EDT

4

"jPMorgan

ATTN: Chris Koscinski / ACA CLO 2007-1 LTD
Primary Recipient(s):
Chris Koscinski / ACA CLO 2007-1 LTD
To: The Financial Institutions Party to the DOMTAR CORPORATION Credit Agreement
Rate Set Notification
Please be advised of the following interest rate set:

Borrower: Deal CUSIP: Deal ISIN: Facility: Facility CUSIP: Facility ISIN: Pricing Type: Date:
Total Amount: Your Share: Interest Period: Tenor:

DOMTAR CORPORATION
25755FAA8
US25755FAA84
800MM TLB
25755FAC4
US25755FAC41
LIBOR
12-APR-07
USD 800,000,000.00
USD 4,000,000.00
From 12-APR-07 To 12-JUL-07
91 Days



Interest Rate:
Margin:
All in Rate:

5.360000% 1.375000% 6.735000%



Interest at Maturity: USD
Your Share: USD

13,619,666.67* 68,098.33

* Interest calculations assume no change to the components
used in the calculation and do not reflect interest payments that may be required prior to the maturing date. You will be notified at maturity of the final interest amount due.
If you have any questions, please contact the undersigned.
Regards,
Sylvia Trevino
JPMorgan Chase Bank
Telephone Number: (713) 750-3536
Facsimile Number: (713) 750-2932
In the event of a telecommunications disruption, our 24 hour back-up number is (877) 580-3675.



我怎样能将Text 导出为XML文件呢,最好是能自定义节点,比如:
<TO>Chris Koscinski / flCfl CLO 2007-1 LTD FROM: JPMC Agent Plus</T0>

就是能自己定义XML的格式。

谢谢了,最好有原代码!!

...全文
222 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
约修亚 2007-07-17
  • 打赏
  • 举报
回复
大家帮帮忙呀 最好有点实例代码

谢谢了
zhchg6666 2007-07-17
  • 打赏
  • 举报
回复
没有直接简单的方法
需要按格式读取,再按格式写入
约修亚 2007-07-17
  • 打赏
  • 举报
回复
谢谢大家了,我已经有个XML,怎样使Txt导出的XML与已经有的一样呢?
karso 2007-07-16
  • 打赏
  • 举报
回复
用dataset 可以直接导入 没有那么麻烦
约修亚 2007-07-16
  • 打赏
  • 举报
回复
谢谢大家了
hy_lihuan 2007-07-16
  • 打赏
  • 举报
回复
你给的样本基本没有什么规律,这样的文本是很难处理的;
你最好保证你文本的规律是强制的,所有文本都是符合的,不然就无法完成你的要求
约修亚 2007-07-16
  • 打赏
  • 举报
回复
DD
约修亚 2007-07-16
  • 打赏
  • 举报
回复
Fax Server

3/30/2007 9:39:32 AM PAGE 1/001 Fax Server

001 AGENCY SERVICES
Date: 29-Mar-2007
TO: ACACLO 2007-1, LTD. ATTN: Daniel Drake Fax:281-667-3741
Re: RENFRO CORPORATION, TRANCHE E TERM LOAN
Description: Scheduled Commitment Decrease
Effective 30-Mar-2007, the borrower's commitment will be reduced from USD 144,725,000.00 to USD 144,450,000.00.
Your share of the commitment will be reduced from USD 1,000,000.00 to USD 998,099.84.
Thanks and regards,
EOEEY WEIL Telephone #: 972-401-8514 Fax #: 972-401-8557




真谢谢大家了,比如我的文本是这样的,
以冒号前的为元素例如:<Date></Date>
还有,如果有空白行,或者没有冒号的行要以行号为元素,请问我该怎么做呢,

最好有些代码

谢谢了
anncesky 2007-07-14
  • 打赏
  • 举报
回复
....有很多问题嘀
要看你的txt文件是none border表形式,还是直接以行符做标识了
sendling 2007-07-14
  • 打赏
  • 举报
回复
补充发刚才的代码,经过自己测试
要引用using System.Xml;
可能找不到路径
1.把 xmlDoc.Load("bookstore.xml");
改为
xmlDoc.Load(Server.MapPath("bookstore.xml"));
2.
xmlDoc.Save("bookstore.xml");改为
xmlDoc.Save(Server.MapPath("bookstore.xml"));

chuxue1342 2007-07-14
  • 打赏
  • 举报
回复
dim doc as new xmldocument
doc.loadXML("你的内容")
doc.save("文件名")
vainnetwork 2007-07-14
  • 打赏
  • 举报
回复
读区文本文件,自己按照自己的想法,写入XML文件就可以了
hyl8218 2007-07-14
  • 打赏
  • 举报
回复
mark
sendling 2007-07-14
  • 打赏
  • 举报
回复
参考以下一些东西先
1.写到文本
StreamWriter myWriter=new StreamWriter(yourPath,false,System.
Text.Encoding.GetEncoding("gb2312"));
myWriter.Write(textbox1.Text);
myWriter.Close();
2.在C#中操作XML一些基础(参考网上)
我用的是一种很笨的方法,但可以帮助初学者了解访问XML节点的过程。

已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>

1、往<bookstore>节点中插入一个<book>节点:
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//查找<bookstore>
XmlElement xe1=xmlDoc.CreateElement("book");//创建一个<book>节点
xe1.SetAttribute("genre","李赞红");//设置该节点genre属性
xe1.SetAttribute("ISBN","2-3631-4");//设置该节点ISBN属性

XmlElement xesub1=xmlDoc.CreateElement("title");
xesub1.InnerText="CS从入门到精通";//设置文本节点
xe1.AppendChild(xesub1);//添加到<book>节点中
XmlElement xesub2=xmlDoc.CreateElement("author");
xesub2.InnerText="候捷";
xe1.AppendChild(xesub2);
XmlElement xesub3=xmlDoc.CreateElement("price");
xesub3.InnerText="58.3";
xe1.AppendChild(xesub3);

root.AppendChild(xe1);//添加到<bookstore>节点中
xmlDoc.Save("bookstore.xml");
//===============================================
结果为:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
<book genre="李赞红" ISBN="2-3631-4">
<title>CS从入门到精通</title>
<author>候捷</author>
<price>58.3</price>
</book>
</bookstore>

2、修改节点:将genre属性值为“李赞红“的节点的genre值改为“update李赞红”,将该节点的子节点<author>的文本修改为“亚胜”。
XmlNodeList nodeList=xmlDoc.SelectSingleNode("bookstore").ChildNodes;//获取bookstore节点的所有子节点
foreach(XmlNode xn in nodeList)//遍历所有子节点
{
XmlElement xe=(XmlElement)xn;//将子节点类型转换为XmlElement类型
if(xe.GetAttribute("genre")=="李赞红")//如果genre属性值为“李赞红”
{
xe.SetAttribute("genre","update李赞红");//则修改该属性为“update李赞红”

XmlNodeList nls=xe.ChildNodes;//继续获取xe子节点的所有子节点
foreach(XmlNode xn1 in nls)//遍历
{
XmlElement xe2=(XmlElement)xn1;//转换类型
if(xe2.Name=="author")//如果找到
{
xe2.InnerText="亚胜";//则修改
break;//找到退出来就可以了
}
}
break;
}
}

xmlDoc.Save("bookstore.xml");//保存。
//==================================================
最后结果为:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
<book genre="update李赞红" ISBN="2-3631-4">
<title>CS从入门到精通</title>
<author>亚胜</author>
<price>58.3</price>
</book>
</bookstore>

3、删除 <book genre="fantasy" ISBN="2-3631-4">节点的genre属性,删除 <book genre="update李赞红" ISBN="2-3631-4">节点。
XmlNodeList xnl=xmlDoc.SelectSingleNode("bookstore").ChildNodes;

foreach(XmlNode xn in xnl)
{
XmlElement xe=(XmlElement)xn;
if(xe.GetAttribute("genre")=="fantasy")
{
xe.RemoveAttribute("genre");//删除genre属性
}
else if(xe.GetAttribute("genre")=="update李赞红")
{
xe.RemoveAll();//删除该节点的全部内容
}
}
xmlDoc.Save("bookstore.xml");
//===========================================
最后结果为:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
<book>
</book>
</bookstore>

4、显示所有数据。
XmlNode xn=xmlDoc.SelectSingleNode("bookstore");

XmlNodeList xnl=xn.ChildNodes;

foreach(XmlNode xnf in xnl)
{
XmlElement xe=(XmlElement)xnf;
Console.WriteLine(xe.GetAttribute("genre"));//显示属性值
Console.WriteLine(xe.GetAttribute("ISBN"));

XmlNodeList xnf1=xe.ChildNodes;
foreach(XmlNode xn2 in xnf1)
{
Console.WriteLine(xn2.InnerText);//显示子节点点文本
}
}
Jinglecat 2007-07-14
  • 打赏
  • 举报
回复
一个字符一个字符,读取,按自己预定义关键字分析,

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧