XML : XML namespaces & their usage

I am trying to add the following namespace to my XML document (document that I create).

  <IP_CustomTransactionLogic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    

Where afterwards I need to use the namespace in one of the values as following:

  <ExpectedValue xsi:type="xsd:string">SomeValue</ExpectedValue>    

I can create XML document without a problem. However I cannot find anywhere how to add and actually use the namespace. Here is my code:

      Public Sub InitializeClass()          Dim xHeader As IXMLDOMProcessingInstruction 'Header instructions            '-----------------------------          'Document Initializer          '-----------------------------          'initialize our XML object with the Root Node          Set xObject = New DOMDocument60            ' Creates root element          Set xRoot = xObject.createElement("IP_CustomTransactionLogic")          xObject.appendChild xRoot            '-----------------------------          'User Creation          '-----------------------------          ' Create default Company          Dim sUser As IXMLDOMElement          Set sUser = xObject.createElement("SelectedCompanyName")          sUser.Text = "VRD"              xRoot.appendChild sUser                '-----------------------------          'Encoding Creation          '-----------------------------          'now create header encoding description          Set xHeader = xObject.createProcessingInstruction("xml", _               "version=""1.0"" encoding=""UTF-8""")          Call xObject.InsertBefore(xHeader, xObject.ChildNodes.Item(0)) 'insert description into document              Set xRepository = xRoot.appendChild(xObject.createElement("CustomBindings"))        End Sub    

For the reference, I am creating the following XML document (just few lines)

  <?xml version="1.0"?>  <IP_CustomTransactionLogic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <SelectedCompanyName>Street</SelectedCompanyName>    <CustomBindings>      <IP_CustomBindings>        <Bindings>          <IP_CustomBindings_OT>            <IP_PropertyName>TransactionDescription</IP_PropertyName>            <ExpectedValue xsi:type="xsd:string">300715 PLATBY POS</ExpectedValue>    

I have tried xObject.SetProperty and xObject.addNamespaces, however none of them worked.

Any help would be highly appreciated

No comments:

Post a Comment