473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Specifying the Default Namespace

JT
Hi all,
I have a pretty basic question... I have a method (below) which uses
ExecuteXMLReader to load the output from a FOR XML Explicit stored procedure
into an XML document, and then save the document to a file. It works well.
Now, I am trying to add namespace support, and want my namespace to be
something like "http://MapTo837P". How do I get this incorporated into the
XML document?
Thanks.
With sqlCmdSendClaims
.Parameters("@NPID").Value = NPIDCursor

Dim doc As New XmlDocument
cnSA.Open()
Dim myXmlReader As XmlTextReader = .ExecuteXmlReader()
myXmlReader.WhitespaceHandling = WhitespaceHandling.None
doc.Load(myXmlReader)
'close the XmlReader when finished.
myXmlReader.Close()
cnSA.Close()
doc.Save("D:\BTS\" & strFileLoc & "claim in\" & NPIDCursor & ".xml")

End With
--
John
Nov 12 '05 #1
3 3455
Hi John,

Thanks for your posting.
AS for the adding namespace for XmlDocument question you mentioned, what
namespace do you means, the default namespace for the xml document's root
element or any arbitary namespace for certain nodes in the document(with or
without prefix).

The .net's XmlDocument didn't provide buildin interfaces for adding
namespaces for all the elemetns in document(including namespace prefix). If
you just want to add a default namespace for the whole XmlDocument, we can
use the XmlAttributes collection to append such as namespace, like:
============
XmlDocument doc = new XmlDocument();
doc.Load(@"..\..\xpath.xml");

XmlAttribute attr = doc.CreateAttribute("xmlns");
attr.Value = "http://www.test.org";

doc.DocumentElement.Attributes.Append(attr);
doc.Save("myoutput.xml");
==============

If there are many namespaces you need to add, and some of them are under
sub nodes(under different hierarchy in the document) and also need to add
namespace prefix for node, I suggest you use XSLT to transform the Document
rather than use the DOM api to modify the XmlDocument.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 12 '05 #2
JT
Thanks Steve. I do mean the default namespace. I am doing the transform in
BizTalk Server 2004, and just trying to improve the interface between it and
my SQL Server datasource.
JT

"Steven Cheng[MSFT]" wrote:
Hi John,

Thanks for your posting.
AS for the adding namespace for XmlDocument question you mentioned, what
namespace do you means, the default namespace for the xml document's root
element or any arbitary namespace for certain nodes in the document(with or
without prefix).

The .net's XmlDocument didn't provide buildin interfaces for adding
namespaces for all the elemetns in document(including namespace prefix). If
you just want to add a default namespace for the whole XmlDocument, we can
use the XmlAttributes collection to append such as namespace, like:
============
XmlDocument doc = new XmlDocument();
doc.Load(@"..\..\xpath.xml");

XmlAttribute attr = doc.CreateAttribute("xmlns");
attr.Value = "http://www.test.org";

doc.DocumentElement.Attributes.Append(attr);
doc.Save("myoutput.xml");
==============

If there are many namespaces you need to add, and some of them are under
sub nodes(under different hierarchy in the document) and also need to add
namespace prefix for node, I suggest you use XSLT to transform the Document
rather than use the DOM api to modify the XmlDocument.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 12 '05 #3
Thanks for your followup.

If so, I think using the XmlNode's Attributes collection to manually set
the default namespace is a possbile approach. Have you met any further
problems ? If so, please feel free to post here.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
10
by: Amittai Aviram | last post by:
This XHTML 1.0 Strict page -- http://www.studiolirico.org/docs/settimana2003.html has a bilingual title in Italian and English. The principle language of the page is Italian, so the <html> tag...
5
by: Adam Child | last post by:
Hi All, I'm trying to validate an xml document. I'm having trouble setting the default namespace of the xml document. If I hard encode the namespace in the xml file then everything works fine....
1
by: Serve Laurijssen | last post by:
Is there a difference between the following cases? using namespace System::Drawing; Pen __gc *pen = new Pen(Color::Black); //******************************* using namespace...
1
by: Scott J. Peterson, MCSD, MCPSB, MCT | last post by:
I'm trying to emulate passing the 'SERVER' parameter in an NSLOOKUP using the Dns namespace, but I don't see anywhere this can be set. For example, I may do this; IPHostEntry ipEntry =...
2
by: UJ | last post by:
What's the general feeling on using the using keyword versus spelling the type out completely. For instance, do most people put a using in so they can just say MyNewType or do people not use...
12
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST>
2
by: shumaker | last post by:
I'm confused about the default namespace setting in the project properties. Help has the following: "Default namespace Specifies the base namespace for all files in the project. For example,...
1
by: Adam Eccleshall | last post by:
Hi, I'm trying to write a routine to extract results from a web service written in VS 2005 using XPath, however VS doesn't put a prefix on result namespaces by default, so in the output from a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.