HighTechTalks DotNet Forums  

Xml document Node with Multiple NameSpace

Dotnet XML microsoft.public.dotnet.xml


Discuss Xml document Node with Multiple NameSpace in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
bhu
 
Posts: n/a

Default Xml document Node with Multiple NameSpace - 08-10-2006 , 09:35 AM






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_ID> some 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





Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: Xml document Node with Multiple NameSpace - 08-10-2006 , 10:09 AM








bhu wrote:


Quote:
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"

Quote:
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/


Reply With Quote
  #3  
Old   
bhu
 
Posts: n/a

Default Re: Xml document Node with Multiple NameSpace - 08-10-2006 , 11:24 AM



Cool This worked.
Thank you.
bhu.

"Martin Honnen" <mahotrash (AT) yahoo (DOT) de> wrote

Quote:

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/



Reply With Quote
  #4  
Old   
bhu
 
Posts: n/a

Default Re: Xml document Node with Multiple NameSpace - 08-11-2006 , 08:58 AM



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 (AT) yahoo (DOT) de> wrote

Quote:

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/



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.