Xml document Node with Multiple NameSpace

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

    Xml document Node with Multiple NameSpace

    Hi
    i am trying some things in XML for webservices but got stuck with the xml
    Creation.
    This is the First Sample
    C# Code
    XmlDocument oInvDocument = new XmlDocument();
    oNode=
    oInvDocument.Cr eateNode(XmlNod eType.Element," InventoryUpdate Batch","");
    oInvDocument.Ap pendChild(oNode );

    output >>>>
    <iu:InventoryUp dateBatch
    xmlns:iu="http://www.abc.com/integrations/schema/InventoryUpdate "
    xmlns:th="http://www.abc.com/integrations/schema/TransactionHead er"
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocat ion="http://www.abc.com/integrations/schema/InventoryUpdate
    C:\Temp\ws\xsd\ InventoryUpdate .xsd">
    <InventoryUpdat e>
    <TransactionHea der>
    ............... ...........

    1.how to add multiple NameSpace to the XML, the code above will add only
    the Element, i don;t know to add the ns?
    2. Let us say i have a DataSet which is named "InventoryUpdat eBatch" and
    has table InventoryUpdate and TransactionHead er when i saveas xml i get the
    xml but i want
    with namespace ? and also some of the element let us say should come with
    ": " <th:Client_IDso me thing like this, if i say the table name to be
    th:client_Id i get the xml as
    <th_x00A_Client _ID>.

    any ideas please ?
    Thanks
    bhu




  • Martin Honnen

    #2
    Re: Xml document Node with Multiple NameSpace



    bhu wrote:

    output >>>>
    <iu:InventoryUp dateBatch
    xmlns:iu="http://www.abc.com/integrations/schema/InventoryUpdate "
    xmlns:th="http://www.abc.com/integrations/schema/TransactionHead er"
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocat ion="http://www.abc.com/integrations/schema/InventoryUpdate
    C:\Temp\ws\xsd\ InventoryUpdate .xsd">
    1.how to add multiple NameSpace to the XML, the code above will add only
    the Element, i don;t know to add the ns?
    Here is an example:

    const string iu =
    "http://www.abc.com/integrations/schema/InventoryUpdate ", th =
    "http://www.abc.com/integrations/schema/TransactionHead er", xmlns =
    "http://www.w3.org/2000/xmlns/", xsi =
    "http://www.w3.org/2001/XMLSchema-instance";

    XmlDocument xmlDocument = new XmlDocument();
    XmlElement inventoryUpdate Batch = xmlDocument.Cre ateElement("iu" ,
    "InventoryUpdat eBatch", iu);

    XmlAttribute thNamespace = xmlDocument.Cre ateAttribute("x mlns:th",
    xmlns);
    thNamespace.Val ue = th;
    inventoryUpdate Batch.SetAttrib uteNode(thNames pace);

    XmlAttribute xsiNamespace =
    xmlDocument.Cre ateAttribute("x mlns:xsi", xmlns);
    xsiNamespace.Va lue = xsi;
    inventoryUpdate Batch.SetAttrib uteNode(xsiName space);

    inventoryUpdate Batch.SetAttrib ute("schemaLoca tion", xsi,
    @"http://www.abc.com/integrations/schema/InventoryUpdate
    C:\Temp\ws\xsd\ InventoryUpdate .xsd");

    xmlDocument.App endChild(invent oryUpdateBatch) ;

    xmlDocument.Sav e("file.xml") ;

    File will the be

    <iu:InventoryUp dateBatch
    xmlns:th="http://www.abc.com/integrations/schema/TransactionHead er"
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocat ion="http://www.abc.com/integrations/schema/InventoryUpdate
    C:\Temp\ws\xsd\ InventoryUpdate .xsd"
    xmlns:iu="http://www.abc.com/integrations/schema/InventoryUpdate " />


    --

    Martin Honnen --- MVP XML

    Comment

    • bhu

      #3
      Re: Xml document Node with Multiple NameSpace

      Cool This worked.
      Thank you.
      bhu.

      "Martin Honnen" <mahotrash@yaho o.dewrote in message
      news:%23SieL8Iv GHA.3364@TK2MSF TNGP02.phx.gbl. ..
      >
      >
      bhu wrote:
      >
      >
      >output >>>>
      ><iu:InventoryU pdateBatch
      >xmlns:iu="http ://www.abc.com/integrations/schema/InventoryUpdate "
      >xmlns:th="http ://www.abc.com/integrations/schema/TransactionHead er"
      >xmlns:xsi="htt p://www.w3.org/2001/XMLSchema-instance"
      >xsi:schemaLoca tion="http://www.abc.com/integrations/schema/InventoryUpdate
      >C:\Temp\ws\xsd \InventoryUpdat e.xsd">
      >
      >
      >1.how to add multiple NameSpace to the XML, the code above will add only
      >the Element, i don;t know to add the ns?
      >
      Here is an example:
      >
      const string iu =
      "http://www.abc.com/integrations/schema/InventoryUpdate ", th =
      "http://www.abc.com/integrations/schema/TransactionHead er", xmlns =
      "http://www.w3.org/2000/xmlns/", xsi =
      "http://www.w3.org/2001/XMLSchema-instance";
      >
      XmlDocument xmlDocument = new XmlDocument();
      XmlElement inventoryUpdate Batch = xmlDocument.Cre ateElement("iu" ,
      "InventoryUpdat eBatch", iu);
      >
      XmlAttribute thNamespace = xmlDocument.Cre ateAttribute("x mlns:th",
      xmlns);
      thNamespace.Val ue = th;
      inventoryUpdate Batch.SetAttrib uteNode(thNames pace);
      >
      XmlAttribute xsiNamespace = xmlDocument.Cre ateAttribute("x mlns:xsi",
      xmlns);
      xsiNamespace.Va lue = xsi;
      inventoryUpdate Batch.SetAttrib uteNode(xsiName space);
      >
      inventoryUpdate Batch.SetAttrib ute("schemaLoca tion", xsi,
      @"http://www.abc.com/integrations/schema/InventoryUpdate
      C:\Temp\ws\xsd\ InventoryUpdate .xsd");
      >
      xmlDocument.App endChild(invent oryUpdateBatch) ;
      >
      xmlDocument.Sav e("file.xml") ;
      >
      File will the be
      >
      <iu:InventoryUp dateBatch
      xmlns:th="http://www.abc.com/integrations/schema/TransactionHead er"
      xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocat ion="http://www.abc.com/integrations/schema/InventoryUpdate
      C:\Temp\ws\xsd\ InventoryUpdate .xsd"
      xmlns:iu="http://www.abc.com/integrations/schema/InventoryUpdate " />
      >
      >
      --
      >
      Martin Honnen --- MVP XML
      http://JavaScript.FAQTs.com/

      Comment

      • bhu

        #4
        Re: Xml document Node with Multiple NameSpace

        Thanks Martin for the answer.
        any idea about the 2nd Question ?, i want to ask that question as a new
        subject, before i do i thought i will ask.


        "Martin Honnen" <mahotrash@yaho o.dewrote in message
        news:%23SieL8Iv GHA.3364@TK2MSF TNGP02.phx.gbl. ..
        >
        >
        bhu wrote:
        >
        >
        >output >>>>
        ><iu:InventoryU pdateBatch
        >xmlns:iu="http ://www.abc.com/integrations/schema/InventoryUpdate "
        >xmlns:th="http ://www.abc.com/integrations/schema/TransactionHead er"
        >xmlns:xsi="htt p://www.w3.org/2001/XMLSchema-instance"
        >xsi:schemaLoca tion="http://www.abc.com/integrations/schema/InventoryUpdate
        >C:\Temp\ws\xsd \InventoryUpdat e.xsd">
        >
        >
        >1.how to add multiple NameSpace to the XML, the code above will add only
        >the Element, i don;t know to add the ns?
        >
        Here is an example:
        >
        const string iu =
        "http://www.abc.com/integrations/schema/InventoryUpdate ", th =
        "http://www.abc.com/integrations/schema/TransactionHead er", xmlns =
        "http://www.w3.org/2000/xmlns/", xsi =
        "http://www.w3.org/2001/XMLSchema-instance";
        >
        XmlDocument xmlDocument = new XmlDocument();
        XmlElement inventoryUpdate Batch = xmlDocument.Cre ateElement("iu" ,
        "InventoryUpdat eBatch", iu);
        >
        XmlAttribute thNamespace = xmlDocument.Cre ateAttribute("x mlns:th",
        xmlns);
        thNamespace.Val ue = th;
        inventoryUpdate Batch.SetAttrib uteNode(thNames pace);
        >
        XmlAttribute xsiNamespace = xmlDocument.Cre ateAttribute("x mlns:xsi",
        xmlns);
        xsiNamespace.Va lue = xsi;
        inventoryUpdate Batch.SetAttrib uteNode(xsiName space);
        >
        inventoryUpdate Batch.SetAttrib ute("schemaLoca tion", xsi,
        @"http://www.abc.com/integrations/schema/InventoryUpdate
        C:\Temp\ws\xsd\ InventoryUpdate .xsd");
        >
        xmlDocument.App endChild(invent oryUpdateBatch) ;
        >
        xmlDocument.Sav e("file.xml") ;
        >
        File will the be
        >
        <iu:InventoryUp dateBatch
        xmlns:th="http://www.abc.com/integrations/schema/TransactionHead er"
        xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocat ion="http://www.abc.com/integrations/schema/InventoryUpdate
        C:\Temp\ws\xsd\ InventoryUpdate .xsd"
        xmlns:iu="http://www.abc.com/integrations/schema/InventoryUpdate " />
        >
        >
        --
        >
        Martin Honnen --- MVP XML
        http://JavaScript.FAQTs.com/

        Comment

        Working...