How to add xsi:schemaLocation attribute to XML element

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kaush

    How to add xsi:schemaLocation attribute to XML element

    Hi all,

    I am trying to serialize a C# object into a XML document
    using "XmlSeriali zer" class. One of the elements of the XML document
    needs a "xsi:schemaLoca tion" attribute. I am not sure how to add this
    to the XML element
    Please help me with if you can.

    Thanks,
    kaush

  • JMD

    #2
    Re: How to add xsi:schemaLocat ion attribute to XML element

    The root element of the document can contain, along with all the xmlns
    stuff, an attribute called
    xsi:schemaLocat ion="namespaceU RI filename.xsd"

    There are two tokens inside the single string. This is a hint for the
    validator to know where to find a physical xsd file to go with that
    namespace.

    --John

    Comment

    • kaush

      #3
      Re: How to add xsi:schemaLocat ion attribute to XML element

      If I add it to the root element of the element for which I need to add
      the xsi:schemaLocat ion attribute, it does not seem to be working.

      Below is the partial XML doc:

      <ProcessMessa ge
      xmlns="http://www.starstandar ds.org/webservices/2003/12/transport">
      <payload
      xmlns="http://www.starstandar ds.org/webservices/2003/12/transport">
      <Content id="Content0">
      <rey_ServiceSta tusRequest
      xmlns="http://www.starstandar ds.org/STAR"> ...this goes on .
      "rey_ServiceSta tusRequest" parent is "Content"


      I need to add the xsi:schemaLocat ion attribute to
      "rey_ServiceSta tusRequest" element. Actually this XML document I
      produce it from a C# object. I use XMLSERIALIZE class to serialize the
      object into XML document. For some reason I am not able to add the
      xsi:schemaLocat ion attribute. I am able to add schemaLocation attribute
      without the "xsi" prefix. I am able to do this using
      //[System.Xml.Seri alization.XmlAt tributeAttribut e(DataType="any URI")].
      This declaration is for a particular memeber of the class.

      Could you please help me out ?

      The only other option I have is to construct the XML doc "element" by
      "element" which I do not want to do.

      Please help

      Comment

      Working...