Function to Get Element List of XML :
public List<string> getElements(string xmlfile)
{
List<string> ElementList = new List<string>();
XmlReader reader = XmlReader.Create(new StringReader(xmlfile));
while (reader.Read())
{
if (reader.NodeType.Equals(XmlNodeType.Element))
{
ElementList.Add(reader.Name);
}
}
return ElementList;
}
Function to Get List of Attribute Name XML :
public List<String> getAttributeName(string xmlfile)
{
List<string> AttributeNameList = new List<string>();
XmlReader reader = XmlReader.Create(new StringReader(xmlfile));
while (reader.Read())
{
if (reader.NodeType.Equals(XmlNodeType.Element))
{
if (reader.HasAttributes)
{
for (int attInd = 0; attInd < reader.AttributeCount; attInd++)
{
reader.MoveToAttribute(attInd);
AttributeNameList.Add(reader.Name);
}
}
}
}
return AttributeNameList;
}
Function to Get List of Attribute Value XML :
public List<String> getAttributeValue(string xmlfile)
{
List<string> AttributeValueList = new List<string>();
XmlReader reader = XmlReader.Create(new StringReader(xmlfile));
while (reader.Read())
{
if (reader.NodeType.Equals(XmlNodeType.Element))
{
if (reader.HasAttributes)
{
for (int attInd = 0; attInd < reader.AttributeCount; attInd++)
{
reader.MoveToAttribute(attInd);
AttributeValueList.Add(reader.Value);
}
}
}
}
return AttributeValueList;
}
No comments:
Post a Comment