Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2010, 12:15 PM
Authorized User
 
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default C# XML File Split

Hi,

We need to Split the XML files based on the Element "CASE". While splitting it is converting Hexadecimal entities into UTF entities. We're new to this, you can understand our level of standard by analyzing the codings.

Please see the XML file and Csharp File for xml Conversion.

XML File
Code:
<ROOT>
<CASE>
<TB>U. S. DISTRICT COURT, EASTERN DISTRICT OF TEXAS</TB>
<LC>CAMPBELL V. WATTS</LC>, <DN>No. 70</DN>, <DD>Feb. 23, 1942</DD>
<SL>FAIR LABOR STANDARDS ACT</SL>
<DE>&#x2014; Overtime standard &#x2014; Burden of proof&#x2014;Evidence</DE>
<PA>In action to recover unpaid overtime compensation under Act, employee has burden of showing with definiteness and certainty that he worked overtime.</PA>
</CASE>
<CASE>
<TB>2nd Chance</TB>
<LC>CAMPBELL V. WATTS</LC>, <DN>No. 70</DN>, <DD>Feb. 23, 1942</DD>
<SL>FAIR LABOR STANDARDS ACT</SL>
<DE>&#x2014; Overtime standard &#x2014; Burden of proof&#x2014;Evidence</DE>
<PA>In action to recover unpaid overtime compensation under Act, employee has burden of showing with definiteness and certainty that he worked overtime.</PA>
</CASE>
</ROOT>
CSharp Coding
Code:
XmlDocument xmlReXML = new XmlDocument();
xmlReXML.Load(@"c:\Shorttag.xml");

XmlNodeList xnRep = xmlReXML.DocumentElement.GetElementsByTagName("CASE");

string strFileName = "CASE";
int intFileCount;

for(int i =0; i <xnRep.Count;i++)
{
              //Stores the CASE Elements in the Variable
              strDest = xnRep[i].InnerXml;

              //Create the New File with the name "CASE_1.xml" and "CASE_3.xml" 
              XmlWriter xw = XmlWriter.Create(strFileName + "_" + intFileCount + ".xml");

              //Write the XML
              xw.WriteRaw(strDest.ToString());

              xw.Close();

              intFileCount++;
}
Current Output
Code:
<?xml version="1.0" encoding="utf-8"?><TB>U. S. DISTRICT COURT, EASTERN DISTRICT OF TEXAS</TB><LC>CAMPBELL V. WATTS</LC>, <DN>No. 70</DN>, <DD>Feb. 23, 1942</DD><SL>FAIR LABOR STANDARDS ACT</SL><DE>— Overtime standard — Burden of proof—Evidence</DE><PA>In action to recover unpaid overtime compensation under Act, employee has burden of showing with definiteness and certainty that he worked overtime.</PA><PA>Evidence held not to show with definiteness and certainty that employee worked an average of 16 hours a day as he claims, precluding him from recovering from employer overtime compensation under Act.</PA>
We need to split the xml file by retaining the entities and also its structure(entermarks) like the original.

Expecting your kind support to solve this..
 
Old May 24th, 2010, 12:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there..

And your problem is????
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old May 25th, 2010, 02:18 AM
Authorized User
 
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default RE: C# XML File Split

Hi,

From our Csharp code, we can successfully split the XML file but the problem is we have to retain the entities as in the original file (e.g., &#x2014; instead of —) and also its structures (you can see the XML Elements is wraped).

This is the summary of the problem we're facing. Please suggest how to solve this. If you need any other information, kindly let us know

Thanks,
 
Old May 26th, 2010, 06:43 AM
Authorized User
 
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default C# XML File Split

Dear All,

Kindly look into these post and help us how to avoid UTF encoding rather than &#x2014; which is our client requirement.
 
Old May 26th, 2010, 07:15 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Basically references are treated the same as the characters themselves when the file is read so what you want is not possible for all circumastances as it's not possible to tell which characters were represented which way. If you know that the output must be in a specific character set then you can specify this using the XmlWriterSettings Encoding property. http://msdn.microsoft.com/en-us/libr...z3(VS.80).aspx
__________________
Joe
http://joe.fawcett.name/
 
Old May 27th, 2010, 08:00 AM
Authorized User
 
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default C# XML File Split Solution

Thanks joefawcett for your suggestion to use XMLWritter Settings to write XML file.

We have modified our coding by using writter settings:

::CSharp Code::
Code:
XmlDocument xmlReXML = new XmlDocument();
xmlReXML.Load(@"c:\Shorttag.xml");

xmlReXML.PreserveWhitespace = true;

XmlNodeList xnRep = xmlReXML.DocumentElement.GetElementsByTagName("CASE");

string strFileName = "CASE";
int intFileCount;

for(int i =0; i <xnRep.Count;i++)
{
              //Stores the CASE Elements in the Variable
              strDest = xnRep[i].InnerXml;


		//Initialize the XMLWritter class settings
                XmlWriterSettings xwsettings = new XmlWriterSettings();
                xwsettings.CheckCharacters = true;
                xwsettings.CloseOutput = false;
                xwsettings.ConformanceLevel = ConformanceLevel.Fragment;
                xwsettings.NewLineChars = Environment.NewLine;
                xwsettings.NewLineOnAttributes = false;
                xwsettings.NewLineHandling = NewLineHandling.Entitize;
                xwsettings.OmitXmlDeclaration = true;
                xwsettings.Encoding = Encoding.ASCII;	

              //Create the New File with the name "CASE_1.xml" and "CASE_3.xml" 
              XmlWriter xw = XmlWriter.Create(strFileName + "_" + intFileCount + ".xml", xwsettings);

              //Write the XML
              xw.WriteString(strDest.ToString());

              xw.Close();

              intFileCount++;
}
Note: Using the above code we will retain the existing entities. The only drawback with the above code is that it will automatically convert the &lt;, &gt; for <> angle brackets tags also.

We Hope the above code will help some others whose objective is to split the XML file and retain the Entities in the XML file.
 
Old May 27th, 2010, 08:30 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think that's because you are using the WriteString method combined with storing the InnerXml in a string.

I would have done the whole transformation via XSLT but as an alternative you could use an XmlReader and use the WriteNode method instead: http://msdn.microsoft.com/en-us/library/1wd6aw1b.aspx
__________________
Joe
http://joe.fawcett.name/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Split large XML to smalls nzvtvsky9 XSLT 1 January 13th, 2010 01:48 PM
Split xml file with result document and javax.xml.transform.Transformer. nisargmca XSLT 3 January 12th, 2010 06:26 AM
How to split resource file prashant.sshrimal ASP.NET 2.0 Professional 0 September 26th, 2009 01:06 AM
Split PostScript file / Print PS to PS saebe Pro VB 6 1 February 27th, 2006 11:02 AM
Split large file to chunks eelisMX Pro VB.NET 2002/2003 4 February 8th, 2005 04:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.