string 문자열의 xml 파싱

string 문자열의 xml 파싱

XML

<?xml version="1.0" encoding="UTF-8"?>
<Data>
	<CustomerName>이름</CustomerName>
	<OrderList>
		<OrderData>
			<OrderName>주문1<OrderName>
		</OrderData>
		<OrderData>
			<OrderName>주문2<OrderName>
		</OrderData>
	</OrderList>
</Data>

단품 항목의 값을 취득

using System.Xml;


string xml = {파싱할 XML 문자열};

XmlDocument xml = new XmlDocument();
xml.LoadXml(xml);

var customerName = node.SelectNodes("CustomerName")[0].InnerText;

리스트 항목의 값을 취득

using System.Xml;


string xml = {파싱할 XML 문자열};

XmlDocument xml = new XmlDocument();
xml.LoadXml(xml);

XmlNodeList nodeList = xml.SelectNodes("/Data/OrderList/OrderData");

if (nodeList.Count > 0)
{
	foreach (XmlNode node in nodeList)
	{
		orderName = node.SelectNodes("OrderName")[0].InnerText;
	}
}

Pie's Tech Note

생계형 개발자의 메모장

comments powered by Disqus

    rss facebook twitter github youtube mail spotify instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora