ASP.NET : Get Attribute Value from XML
-
Hi Experts, My Xml is :
<?xml version="1.0" encoding="utf-8"?>
<Sis xsi:noNamespaceSchemaLocation="Sis.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Student>
<StudentID>1</StudentID>
<AcademicDetails>2008-2009</AcademicDetails>
<PersonalDetails>
<FirstName>Vijay</FirstName>
<MiddleName>Laxmanrao</MiddleName>
<LastName>Jadhav</LastName>
</PersonalDetails>
</Student>
</Sis>I need to extract the value of xsi:noNamespaceSchemaLocation (ie. Sis.xsd). How to get it ? I have try below snippet, but it will show sXSDFile always null. Why ?
public static bool ValidateXml(Stream oXmlStream) { string sXsdPath = ""; string sXSDFile = ""; try { XmlTextReader xmlTextReader = new XmlTextReader(oXmlStream); sXSDFile = xmlTextReader.GetAttribute("xsi:noNamespaceSchemaLocation"); } catch (Exception ex) { \_isValied = false; } return \_isValied; }
Sample code would be greatly appreciated.:thumbsup: Thanks.
Vijay Jadhav.
-
Hi Experts, My Xml is :
<?xml version="1.0" encoding="utf-8"?>
<Sis xsi:noNamespaceSchemaLocation="Sis.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Student>
<StudentID>1</StudentID>
<AcademicDetails>2008-2009</AcademicDetails>
<PersonalDetails>
<FirstName>Vijay</FirstName>
<MiddleName>Laxmanrao</MiddleName>
<LastName>Jadhav</LastName>
</PersonalDetails>
</Student>
</Sis>I need to extract the value of xsi:noNamespaceSchemaLocation (ie. Sis.xsd). How to get it ? I have try below snippet, but it will show sXSDFile always null. Why ?
public static bool ValidateXml(Stream oXmlStream) { string sXsdPath = ""; string sXSDFile = ""; try { XmlTextReader xmlTextReader = new XmlTextReader(oXmlStream); sXSDFile = xmlTextReader.GetAttribute("xsi:noNamespaceSchemaLocation"); } catch (Exception ex) { \_isValied = false; } return \_isValied; }
Sample code would be greatly appreciated.:thumbsup: Thanks.
Vijay Jadhav.
Hi All, I got it. Code snippet : XmlTextReader xmlTextReader = new XmlTextReader(oXmlStream); xmlTextReader.MoveToContent(); sGetXsdFileName = xmlTextReader.GetAttribute("xsi:noNamespaceSchemaLocation"); Thanks. :laugh:
Vijay Jadhav.