| |

VerySource

 Forgot password?
 Register
Search
View: 606|Reply: 4

xml problem

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-6 23:30:01
| Show all posts |Read mode
The xml file format is as follows
<? xml version = "1.0" encoding = "utf-8"?>
<Vocation>
<VocationTypeFather Value = "1000" Text = "Please select industry category">
<VocationTypeSon Value = "2000" Text = "Please select a job category"> </ VocationTypeSon>
</ VocationTypeFather>
<VocationTypeFather Value = "1001" Text = "Computer Hardware">
<VocationTypeSon Value = "2001" Text = "Network Engineer">
<VocationTypeGrandson Value = "3001" Text = "Wiring Principle"> </ VocationTypeGrandson>
</ VocationTypeSon>
</ VocationTypeFather>
</ Vocation>

Excuse me, if I know the Value property of a node, how to get the Text property of the node, please give the code, thank you
Reply

Use magic Report

0

Threads

29

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-5-26 11:00:01
| Show all posts
Haha, I don't know. Can the value of the node be repeatable? Or is it empty? How to solve this problem of duplication and null value?
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-5-27 00:00:01
| Show all posts
using System.Xml;

////////////////////////////////////


string strText = "";
XmlTextReader xr = new XmlTextReader (Server.MapPath (null) + "\\test.xml");
xr.MoveToAttribute ("Vocation");
while (xr.Read ())
{
    if (xr.Name.Equals ("VocationTypeFather"))
    {
        if (xr.GetAttribute ("Value") == "1000")
        {
            strText = xr.GetAttribute ("Text");
            break;
        }
    }
}
xr.Close ();
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-5-27 08:15:02
| Show all posts
Value "1000" is written to the variable instead
Reply

Use magic Report

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-5-27 23:00:02
| Show all posts
Thank you for passing the test
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list