|
-
December 10th, 2008, 12:17 AM
#1
read and write XML
Hi all i have xml file need to change that with diffrent languages
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?><WebEditorDocument><Template Name="Test"/><Data><Paragraph Format="Text">The graph applies to a cleaning bend with cleaning cap and with the same dimension of take-off and main duct (Ød<Subscript>3</Subscript>=Ød<Subscript>1</Subscript>).</Paragraph><Paragraph Format="Text2">The pressure drop is about 30% lower for cleaning cap and Ød<Subscript>3</Subscript>=Ød<Subscript>1</Subscript>.</Paragraph><Paragraph Format="Text2">The pressure drop is about 30% lower for cleaning cap and one step smaller take-off dimension (Ød<Subscript>3 </Subscript>< Ød<Subscript>1</Subscript>).</Paragraph><Paragraph Format="Text2">The pressure drop is about 50% lower for cleaning cap KCU and one step smaller take-off dimension (Ød<Subscript>3 </Subscript>< Ød<Subscript>1</Subscript>).</Paragraph></Data></WebEditorDocument>
And after the translation the value in the text file should be
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?><WebEditorDocument><Template Name="Test"/><Data><Paragraph Format="Text">Diagrammet avser rensbar böj med renslucka samt med samma dimension på stos och huvudrör (Ød<Subscript>3</Subscript> = Ød<Subscript>1</Subscript>).</Paragraph><Paragraph Format="Text2">För renslucka samt Ød<Subscript>3</Subscript> = Ød<Subscript>1</Subscript>, är tryckfallet ca 30% <Break/>lägre.</Paragraph><Paragraph Format="Text">För renslucka samt ett stegs mindre stosdimension (Ød<Subscript>3</Subscript> < Ød<Subscript>1</Subscript>) är tryckfallet ca 30% lägre.</Paragraph><Paragraph Format="Text">För renslucka samt ett stegs mindre stosdimension (Ød<Subscript>3</Subscript> < Ød<Subscript>1</Subscript>) är tryckfallet ca 50% lägre.</Paragraph></Data></WebEditorDocument>
i tried to read the file
Code:
try
{
StringReader srXmlValue = new StringReader(param.ParamValue.Replace("<Break/>", Environment.NewLine));
XmlTextReader trXmlValue = new XmlTextReader(srXmlValue);
while (trXmlValue.Read())
{
switch (trXmlValue.NodeType)
{
case XmlNodeType.Element: // The node is an element.
if (trXmlValue.Name.Trim().ToLower() == "paragraph")
{
txtParamValue.Text += String.Format("[###Paragraph-{0}###]", trXmlValue["Format"]);
txtParamValue.Text += Environment.NewLine;
}
break;
case XmlNodeType.Text: //Display the text in each element.
txtParamValue.Text += Environment.NewLine;
txtParamValue.Text += trXmlValue.Value;
// txtParamValue.Text += Environment.NewLine;
// txtParamValue.Text += Environment.NewLine;
break;
}
}
}
catch
{
txtParamValue.Text = param.ParamValue;
}
but getting problem near <subscript>3</subscript>,
i have to show the entire text in paragraph tag in richtextbox
thanks
-
December 10th, 2008, 03:46 AM
#2
Re: read and write XML
I would suggest to use xPath, you can retrieve an node much easier and you don't need the switch statment
Code:
string richtextbox = "";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("XMLFile1.xml");
XmlNodeList paragraphs = xmlDoc.SelectNodes("WebEditorDocument/Data/Paragraph");
foreach (XmlNode p in paragraphs) {
richtextbox += string.Format("paragraph-{0}", p.Attributes["Format"]);
richtextbox += Environment.NewLine;
//and do the rest of your processing using this xmlNode
}
And second, what exactly are you trying to achieve with the subscript node.?
-
December 10th, 2008, 05:18 AM
#3
Re: read and write XML
Thanks for the reply
Actuall i have to read a text file in that i have this XML for
like this
BBC|2045|132| here the xml text
i have to show the xml text in plain text and after modificatations again rewrite to text file
in the xml i have to show the entire text in paragraph node where i am unable to get this subscript tag
Thanks a lot
-
December 10th, 2008, 07:33 AM
#4
Re: read and write XML
if you use my code, the subscript node can be found in the p.Chilnodes properties
-
December 10th, 2008, 08:54 AM
#5
Re: read and write XML
Hi dannystommen,
Thanks for the reply
i am going in the as specified by you,i am geting complete text by using p.innertext
and after changing the text how can i follow to write it into XML format
Thanks a lot
Last edited by tis707; December 10th, 2008 at 09:15 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|