Results 1 to 2 of 2

Thread: How to add xsi:schemalocation

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    64

    Unhappy How to add xsi:schemalocation

    Creating an xml document with the xsi:schemalocation attribute.
    Everytime i create the file it takes the xsi prefix off! Anyideas why it would do this?

    See Code below


    Code:
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim xmldoc As New System.Xml.XmlDocument
            Dim xmlproc As System.Xml.XmlDeclaration
            Dim xmlroot As System.Xml.XmlElement
            Dim xmlchild As System.Xml.XmlElement
            Dim xmlAttri As System.Xml.XmlAttribute
            Dim xmlOutputfile As New System.Xml.XmlTextWriter("c:\Simplexml.xml", System.Text.Encoding.UTF8)
    
            xmlproc = xmldoc.CreateXmlDeclaration("1.0", "", "")
            xmldoc.AppendChild(xmlproc)
    
            xmlroot = xmldoc.CreateElement("invoice")
    
            xmlAttri = xmldoc.CreateAttribute("xmlns")
            xmlAttri.Value = "http://www.test.info"
            xmlroot.Attributes.Append(xmlAttri)
    
            xmlAttri = xmldoc.CreateAttribute("xmlns:xsi")
            xmlAttri.Value = "http://www.w3.org/2001/XMLSchema-instance"
            xmlroot.Attributes.Append(xmlAttri)
    
    
            xmlAttri = xmldoc.CreateAttribute("schemaLocation")
            xmlAttri.Value = "http://NamespaceTest.com/Purchase test_xml_feed.xsd"
            xmlroot.Attributes.Append(xmlAttri)
    
    
    
            xmlchild = xmldoc.CreateElement("provider_ref")
            xmlchild.InnerText = "1234"
            xmlroot.AppendChild(xmlchild)
    
            xmlchild = xmldoc.CreateElement("supplier_name")
            xmlchild.InnerText = "A Supplier"
            xmlroot.AppendChild(xmlchild)
    
            xmlchild = xmldoc.CreateElement("period")
            xmlchild.InnerText = "2008-05-04"
            xmlroot.AppendChild(xmlchild)
    
            xmlchild = xmldoc.CreateElement("invoice_number")
            xmlchild.InnerText = "000000001"
            xmlroot.AppendChild(xmlchild)
    
            xmlroot.AppendChild(xmlchild)
    
            xmldoc.AppendChild(xmlroot)
    
            xmldoc.WriteTo(xmlOutputfile)
            xmlOutputfile.Close()
    
        End Sub

  2. #2
    New Member
    Join Date
    Nov 2008
    Posts
    1

    Re: How to add xsi:schemalocation

    Hi, i was trying too, but i had very much problem...what do i do?... to use serialization (looking for serialization in google and MSDN) ... this was the only way...

    The following is the header that I used to get the attribute you mention (Visual Basic 2005):
    vb.net Code:
    1. <System.Xml.Serialization.XmlAttribute("schemaLocation", [Namespace]:="http://www.w3.org/2001/XMLSchema-instance")> _
    2.     Public SchemaLocation As String = "http://www.example.gob.mx/ http://www.example.gob.mx/sitio_internet/cxxx2.xsd"
    Check this links with other answers...

    http://bytes.com/forum/thread539595.html
    http://forums.microsoft.com/msdn/Sho...14893&SiteID=1

    Saludos desde México

    Freebyte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width