470,855 Members | 1,172 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Xml document Node with Multiple NameSpace

bhu
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.CreateNode(XmlNodeType.Element,"Inven toryUpdateBatch","");
oInvDocument.AppendChild(oNode);

output >>>>
<iu:InventoryUpdateBatch
xmlns:iu="http://www.abc.com/integrations/schema/InventoryUpdate"
xmlns:th="http://www.abc.com/integrations/schema/TransactionHeader"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.abc.com/integrations/schema/InventoryUpdate
C:\Temp\ws\xsd\InventoryUpdate.xsd">
<InventoryUpdate>
<TransactionHeader>
..........................

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 "InventoryUpdateBatch" and
has table InventoryUpdate and TransactionHeader 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_IDsome 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


Aug 10 '06 #1
3 7934


bhu wrote:

output >>>>
<iu:InventoryUpdateBatch
xmlns:iu="http://www.abc.com/integrations/schema/InventoryUpdate"
xmlns:th="http://www.abc.com/integrations/schema/TransactionHeader"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/TransactionHeader", xmlns =
"http://www.w3.org/2000/xmlns/", xsi =
"http://www.w3.org/2001/XMLSchema-instance";

XmlDocument xmlDocument = new XmlDocument();
XmlElement inventoryUpdateBatch = xmlDocument.CreateElement("iu",
"InventoryUpdateBatch", iu);

XmlAttribute thNamespace = xmlDocument.CreateAttribute("xmlns:th",
xmlns);
thNamespace.Value = th;
inventoryUpdateBatch.SetAttributeNode(thNamespace) ;

XmlAttribute xsiNamespace =
xmlDocument.CreateAttribute("xmlns:xsi", xmlns);
xsiNamespace.Value = xsi;
inventoryUpdateBatch.SetAttributeNode(xsiNamespace );

inventoryUpdateBatch.SetAttribute("schemaLocation" , xsi,
@"http://www.abc.com/integrations/schema/InventoryUpdate
C:\Temp\ws\xsd\InventoryUpdate.xsd");

xmlDocument.AppendChild(inventoryUpdateBatch);

xmlDocument.Save("file.xml");

File will the be

<iu:InventoryUpdateBatch
xmlns:th="http://www.abc.com/integrations/schema/TransactionHeader"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/
Aug 10 '06 #2
bhu
Cool This worked.
Thank you.
bhu.

"Martin Honnen" <ma*******@yahoo.dewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>

bhu wrote:

>output >>>>
<iu:InventoryUpdateBatch
xmlns:iu="http://www.abc.com/integrations/schema/InventoryUpdate"
xmlns:th="http://www.abc.com/integrations/schema/TransactionHeader"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/TransactionHeader", xmlns =
"http://www.w3.org/2000/xmlns/", xsi =
"http://www.w3.org/2001/XMLSchema-instance";

XmlDocument xmlDocument = new XmlDocument();
XmlElement inventoryUpdateBatch = xmlDocument.CreateElement("iu",
"InventoryUpdateBatch", iu);

XmlAttribute thNamespace = xmlDocument.CreateAttribute("xmlns:th",
xmlns);
thNamespace.Value = th;
inventoryUpdateBatch.SetAttributeNode(thNamespace) ;

XmlAttribute xsiNamespace = xmlDocument.CreateAttribute("xmlns:xsi",
xmlns);
xsiNamespace.Value = xsi;
inventoryUpdateBatch.SetAttributeNode(xsiNamespace );

inventoryUpdateBatch.SetAttribute("schemaLocation" , xsi,
@"http://www.abc.com/integrations/schema/InventoryUpdate
C:\Temp\ws\xsd\InventoryUpdate.xsd");

xmlDocument.AppendChild(inventoryUpdateBatch);

xmlDocument.Save("file.xml");

File will the be

<iu:InventoryUpdateBatch
xmlns:th="http://www.abc.com/integrations/schema/TransactionHeader"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/

Aug 10 '06 #3
bhu
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" <ma*******@yahoo.dewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>

bhu wrote:

>output >>>>
<iu:InventoryUpdateBatch
xmlns:iu="http://www.abc.com/integrations/schema/InventoryUpdate"
xmlns:th="http://www.abc.com/integrations/schema/TransactionHeader"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/TransactionHeader", xmlns =
"http://www.w3.org/2000/xmlns/", xsi =
"http://www.w3.org/2001/XMLSchema-instance";

XmlDocument xmlDocument = new XmlDocument();
XmlElement inventoryUpdateBatch = xmlDocument.CreateElement("iu",
"InventoryUpdateBatch", iu);

XmlAttribute thNamespace = xmlDocument.CreateAttribute("xmlns:th",
xmlns);
thNamespace.Value = th;
inventoryUpdateBatch.SetAttributeNode(thNamespace) ;

XmlAttribute xsiNamespace = xmlDocument.CreateAttribute("xmlns:xsi",
xmlns);
xsiNamespace.Value = xsi;
inventoryUpdateBatch.SetAttributeNode(xsiNamespace );

inventoryUpdateBatch.SetAttribute("schemaLocation" , xsi,
@"http://www.abc.com/integrations/schema/InventoryUpdate
C:\Temp\ws\xsd\InventoryUpdate.xsd");

xmlDocument.AppendChild(inventoryUpdateBatch);

xmlDocument.Save("file.xml");

File will the be

<iu:InventoryUpdateBatch
xmlns:th="http://www.abc.com/integrations/schema/TransactionHeader"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/

Aug 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by David Gersic | last post: by
5 posts views Thread by Norsoft | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.