Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

xml read and write

Below codes are tyring to get xml string from actual entire xml file. but now I want to put some conditions.
like I just want to get Application Name="A1" condition. so I suppose to get only Application Name= "A1" of course with all child nodes as well.
How can I modify it?


public static string convertToXmlString(string strFile)
        {
            //Q6: How to get xml string filter by applicationName? need help
            // Load the xml file into XmlDocument object.
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.Load(strFile);                                 
            }
            catch (XmlException e)
            {
                Console.WriteLine(e.Message);
            }
            // Now create StringWriter object to get data from xml document.
            StringWriter sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);
            xmlDoc.WriteTo(xw);
            return sw.ToString();
            
        }

Open in new window


<?xml version="1.0" encoding="utf-8" ?>
<Applications>
  <Application Name="A1" Script="">
    <Q Id="1">
      <Name>What is your favor color?</Name>
      <Control>Select</Control>
      <List>Red,Yellow</List>
      <PdfFieldName>pdfColor</PdfFieldName>
      <HtmlFieldName>selectFavorColor</HtmlFieldName>
      <DefaultHtmlValue>Red</DefaultHtmlValue>      
    </Q>
    <Q Id="2">
      <Name>What is your favor car?</Name>
      <Control>TextBox</Control>
      <List></List>
      <PdfFieldName>pdfCar</PdfFieldName>
      <HtmlFieldName>textFavorCar</HtmlFieldName>
      <DefaultHtmlValue></DefaultHtmlValue>      
    </Q>
    <Q Id="3">
      <Name>What is your favor hobby?</Name>
      <Control>Checkbox</Control>
      <List>Sport,Gamble</List>
      <PdfFieldName>asdfasdf</PdfFieldName>
      <HtmlFieldName>textFavorHobby</HtmlFieldName>
      <DefaultHtmlValue>Sport</DefaultHtmlValue>      
    </Q>
  </Application>
  <Application Name="A2" Script="customScriptA2.js">
    <Q Id="1">
      <Name>What is your favor color?</Name>
      <Control>Select</Control>
      <List>Red,Yellow</List>
      <PdfFieldName>pdfColor</PdfFieldName>
      <HtmlFieldName>selectFavorColor</HtmlFieldName>
      <DefaultHtmlValue>Red</DefaultHtmlValue>      
    </Q>
    <Q Id="2">
      <Name>What is your favor car?</Name>
      <Control>TextBox</Control>
      <List></List>
      <PdfFieldName>pdfCar</PdfFieldName>
      <HtmlFieldName>textFavorCar</HtmlFieldName>
      <DefaultHtmlValue></DefaultHtmlValue>      
    </Q>
    <Q Id="3">
      <Name>What is your favor hobby?</Name>
      <Control>CheckBox</Control>
      <List>Sport,Gamble</List>
      <PdfFieldName>asdfasdf</PdfFieldName>
      <HtmlFieldName>textFavorHobby</HtmlFieldName>
      <DefaultHtmlValue>Sport</DefaultHtmlValue>      
    </Q>
  </Application>
</Applications>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ITsolutionWizard

ASKER

I am old so i pretty old way - XMLdocument please
Then you will need to wait for an expert that knows the old ways.