简体   繁体   中英

How can I display all the Types and Values in my XML file

I have an XML file,all of it with same elements : <field > </field>

Every field has type "XXX" , and also : <value>AAA</value>

I want to display all the types and values in console mode

Examples :

type  : MrzType        type:  DocumentType          ....
Value : 2line          Value: P

I have this code:

XmlDocument Xmldoc = new XmlDocument();
Xmldoc.Load(@"C:\image.xml");

foreach (XmlElement element in Xmldoc.GetElementsByTagName("field"))
{
     if (element.HasAttribute("type"))
     {
           Console.WriteLine("type : " + element.GetAttribute("type"));
     }

     Console.WriteLine("Value : " + element.InnerText);
     Console.ReadLine();
 }

But i have just the result:

type : MrzType Value : 2line

I want to display all types and their values?

This is my file XML ,image.xml:

<document>
<field type="MrzType">
<value>2line</value>
</field>
<field type="DocumentNumber">
<value>R420604</value>
</field>
<field type="DocumentType">
<value>P</value>
</field>
<field type="DocumentSubtype">
<value>&lt;</value>
</field>
<field type="IssuingCountry">
<value>TUN</value>
</field>
<field type="LastName">
<value>THABET</value>
</field>

Thanks,

cut the Console.ReadLine(); line and paste it after }

You must delete Console.ReadLine(); statment.

The loop stop after one itteration. When do this result is:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM