We help IT Professionals succeed at work.

how to read xml file which contains html tags using C# and xmlreader

ziorrinfotech
on
Medium Priority
1,934 Views
Last Modified: 2013-12-17
I have one big xml file which i am reading using xmlreader.
Node of the node of this xml file contains html tags,
and when i read the xml file some times i got error because of this html tags.
Is there any way by which i can read this xml file with out any error
Comment
Watch Question

If you have html tags directly in a node, they should have <![CDATA[]]> tags around the data or it is not proper XML.  The XML Reader will see any <tag> in the HTML and try to process since it is not marked as CDATA.

You could perhaps make a custom DTD to define the node as CDATA, or write your own XMLReader.
Declaring Attributes and Elements in an XML DTD

http://www.rpbourret.com/xml/xmldtd.htm
Anurag ThakurTechnical Manager

Commented:
show us your xml file for a better solution

Author

Commented:
this is node which contains html contents and this node only doing issues for me.
</document_table>Im E-Mail enthalten sind die Rechnungsdokumente als PDF. Als Rechnungsdokumente gelten:
&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;
        Rechnung&amp;nbsp;
    &lt;/li&gt;
    &lt;li&gt;
        ggf. Kostenaufstellung&amp;nbsp;
    &lt;/li&gt;
    &lt;li&gt;
        VBN standard (wenn Zusatzservice aktiviert)&amp;nbsp;
    &lt;/li&gt;
    &lt;li&gt;
        VBN plus (wenn Zusatzservice aktiviert)
    &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
    Falls kein LSV/DD aktiviert: Angabe von:
&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;
        Konto
    &lt;/li&gt;
    &lt;li&gt;
        Rechnungsbetrag
    &lt;/li&gt;
    &lt;li&gt;
        Referenz-Nr., ESR
    &lt;/li&gt;
    &lt;li&gt;
        Einzahlung für: Swisscom Mobile AG, Contact Center MC, CH-3050 Bern
    &lt;/li&gt;
    &lt;li&gt;
        Codierzeile für Belegleser
    &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
    Tipps und Hinweise zur Bezahlung www.swisscommobile.ch/scm/kd_rechnung_per_email-de.aspx Link auf aktuelle
    Rechnungsbeilage www.swisscommobile.ch/natelupdate_d Link auf eflash www.swisscom-mobile.ch/scm/333_newsletterde.aspx
&lt;/p&gt;"></document_table>

Open in new window

Author

Commented:
could you pls tell me CDATA node example.


this is valid
<CDATA> html tags</CDATA>
CERTIFIED EXPERT

Commented:
HI
I Change ur XMl File - Check Attach Code Part.
Then Goto Project file. Select XML File - goto property  Build Action change to "Embedded Resource"
and Copy of output directy change to "Copy always"

In the Cs page add Namespace
using System.Windows.Forms;
using System.Xml;
using System.Reflection;
using System.IO;
class EmailTemplate
    {
        private string _Dataobj = string.Empty;

public string Dataobj
        {
            get
            {
                return _Dataobj;
            }
            set
            {
                _Dataobj = value;

            }
        }

   public EmailTemplate()
        {
            try
            {
                string AppStartpath = Application.StartupPath.ToString() + @"\";
                Assembly SubwizardAsm = Assembly.GetExecutingAssembly();
                Stream xmlStream = SubwizardAsm.GetManifestResourceStream("<Location>.EmailTemplate.xml");
                XmlDataDocument xsd = new XmlDataDocument();
                StreamReader reader = new StreamReader(xmlStream);
                xsd.LoadXml(reader.ReadToEnd());

                //xmlDoc = TrimSpecialCharacters(xmlDoc); //Replace carriage returns and line feed

                XmlNode node = xsd.SelectSingleNode("DataCollection");
                this.Fromobj = node.SelectSingleNode("document_table").InnerXml;
}

<DataCollection>
<document_table>
Im E-Mail enthalten sind die Rechnungsdokumente als PDF. Als Rechnungsdokumente gelten:
</p>
<ul>
    <li>
        Rechnung&amp;nbsp;
    </li>
    <li>
        ggf. Kostenaufstellung&amp;nbsp;
    </li>
    <li>
        VBN standard (wenn Zusatzservice aktiviert)&amp;nbsp;
    </li>
    <li>
        VBN plus (wenn Zusatzservice aktiviert)
    </li>
</ul>
<p>
    Falls kein LSV/DD aktiviert: Angabe von:
</p>
<ol>
    <li>
        Konto
    </li>
    <li>
        Rechnungsbetrag
    </li>
    <li>
        Referenz-Nr., ESR
    </li>
    <li>
        Einzahlung für: Swisscom Mobile AG, Contact Center MC, CH-3050 Bern
    </li>
    <li>
        Codierzeile für Belegleser
    </li>
</ol>
<p>
    Tipps und Hinweise zur Bezahlung www.swisscommobile.ch/scm/kd_rechnung_per_email-de.aspx Link auf aktuelle
    Rechnungsbeilage www.swisscommobile.ch/natelupdate_d Link auf eflash www.swisscom-mobile.ch/scm/333_newsletterde.aspx
</p>"></document_table></DataCollection>

Open in new window

A valid CDATA section is like so:

<DataCollection>
   <document_table>
     <!CDATA[<p>this is your html data</p>]]>
   </document_table>
</DataCollection>

Between the start of the section, "<![CDATA[" and the end of the section, "]]>", all character data is passed directly to the application.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.