Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. ASP.NET : Get Attribute Value from XML

ASP.NET : Get Attribute Value from XML

Scheduled Pinned Locked Moved XML / XSL
csharpasp-netxmltutorialquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vijay Jadhav India
    wrote on last edited by
    #1

    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.

    V 1 Reply Last reply
    0
    • V Vijay Jadhav India

      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.

      V Offline
      V Offline
      Vijay Jadhav India
      wrote on last edited by
      #2

      Hi All, I got it. Code snippet : XmlTextReader xmlTextReader = new XmlTextReader(oXmlStream); xmlTextReader.MoveToContent(); sGetXsdFileName = xmlTextReader.GetAttribute("xsi:noNamespaceSchemaLocation"); Thanks. :laugh:

      Vijay Jadhav.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups