Hello:
I would like to output the following XML Element using the XmlTextWriter,
but I cannot get it correct:
-----------------------------------------------------------------------------------------------
<SOAP-ENV:Body
xmlns:SOAP-SEC="http://schemas.xmlsoap.org/soap/security/2000-12"
SOAP-SEC:id="body">
-----------------------------------------------------------------------------------------------
I have tried the following:
xw.WriteStartElement("SOAP-ENV", "Body", "123");
xw.WriteAttributeString("xmlns", "SOAP-SEC", null,
"http://schemas.xmlsoap.org/soap/security/2000-12");
//xw.WriteAttributeString("SOAP-SEC", "id", null, "body");
xw.WriteAttributeString("SOAP-SEC", "id", "123", "body");
And nothing has worked. I keep getting extra attributes in my element.
What am I missing?
Thanks
Andy 2 2037
"Andy" <An**@discussions.microsoft.com> wrote in message news:D4**********************************@microsof t.com... <SOAP-ENV:Body xmlns:SOAP-SEC="http://schemas.xmlsoap.org/soap/security/2000-12" SOAP-SEC:id="body">
Presumably SOAP-ENV was declared on a parent element, like Envelope,
so it should be possible to produce this literal XML.
I have tried the following: xw.WriteStartElement("SOAP-ENV", "Body", "123");
What is it that "123" is supposed to mean?
Assuming the conventional definition of SOAP-ENV, this will work,
// WriteStartElement( prefix, localName, namespaceUri);
xw.WriteStartElement( "SOAP-ENV", "Body", "http://schemas.xmlsoap.org/soap/envelope/");
When xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" is
already declared on a parent element, no xmlns declaration will be written
for the SOAP-ENV:Body tag. However, if this prefix hasn't been declared
yet then XmlWriter will emit it now.
There's no reason to call,
xw.WriteAttributeString("xmlns", "SOAP-SEC", null, "http://schemas.xmlsoap.org/soap/security/2000-12");
to write an xmlns declaration -- again, the XmlWriter will emit an
xmlns declaration only when it is required (as long as you pass the
correct namespace URI for the prefix when you call
WriteAttributeString( )).
xw.WriteAttributeString("SOAP-SEC", "id", "123", "body");
Hence, this line should become,
// WriteAttributeString( prefix, localName, namespaceURI, attributeValue)
xw.WriteAttributeString( "SOAP-SEC", "id",
"http://schemas.xmlsoap.org/soap/security/2000-12", "body");
And nothing has worked. I keep getting extra attributes in my element. What am I missing?
Only those two lines (and a WriteEndElement( )) are needed. Don't
stress over the xmlns declarations, XmlWriter will handle those for
you automatically if you pass the correct prefixes/namespace URIs
to the WriteStartElement( ) and WriteAttributeString( ) methods.
Derek Harmon
Derek:
Thank you very much for the help. This is exactly what I needed.
To answer your question about the "123": I simply found that example on a
Microsoft webpage, and it was something I was trying. It said the 123 would
be overwritten.
"Derek Harmon" wrote: "Andy" <An**@discussions.microsoft.com> wrote in message news:D4**********************************@microsof t.com... <SOAP-ENV:Body xmlns:SOAP-SEC="http://schemas.xmlsoap.org/soap/security/2000-12" SOAP-SEC:id="body">
Presumably SOAP-ENV was declared on a parent element, like Envelope, so it should be possible to produce this literal XML.
I have tried the following: xw.WriteStartElement("SOAP-ENV", "Body", "123");
What is it that "123" is supposed to mean?
Assuming the conventional definition of SOAP-ENV, this will work,
// WriteStartElement( prefix, localName, namespaceUri); xw.WriteStartElement( "SOAP-ENV", "Body", "http://schemas.xmlsoap.org/soap/envelope/");
When xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" is already declared on a parent element, no xmlns declaration will be written for the SOAP-ENV:Body tag. However, if this prefix hasn't been declared yet then XmlWriter will emit it now.
There's no reason to call,
xw.WriteAttributeString("xmlns", "SOAP-SEC", null, "http://schemas.xmlsoap.org/soap/security/2000-12");
to write an xmlns declaration -- again, the XmlWriter will emit an xmlns declaration only when it is required (as long as you pass the correct namespace URI for the prefix when you call WriteAttributeString( )).
xw.WriteAttributeString("SOAP-SEC", "id", "123", "body");
Hence, this line should become,
// WriteAttributeString( prefix, localName, namespaceURI, attributeValue) xw.WriteAttributeString( "SOAP-SEC", "id", "http://schemas.xmlsoap.org/soap/security/2000-12", "body");
And nothing has worked. I keep getting extra attributes in my element. What am I missing?
Only those two lines (and a WriteEndElement( )) are needed. Don't stress over the xmlns declarations, XmlWriter will handle those for you automatically if you pass the correct prefixes/namespace URIs to the WriteStartElement( ) and WriteAttributeString( ) methods.
Derek Harmon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: T Conti |
last post by:
Howdy:
I am currently writing a .Net handler to replace an ASP page. The ASP
module used a COM dll to format XML. This dll was pretty robust and
it auto-suppressed empty elements and...
|
by: Lee Atkinson |
last post by:
Hi - I am trying to read an XML file using XmlTextReader and write it
out using XmlTextWriter.
The XML is XHTML. At the moment, I am trying to create a straightforward
copy of a file. The XHTML...
|
by: Andrew R. Thomas-Cramer |
last post by:
I'm using XMLTextWriter to write to a socket stream. I need to write the
opening root tag immediately for receipt by the client; elements beneath
it will come later.
...
|
by: Einar Høst |
last post by:
Hi,
I'm having weird problems using StringWriter and XmlTextWriter. My code
looks like this:
StringWriter sw = new StringWriter(CultureInfo.InvariantInfo);
XmlTextWriter xtw = new...
|
by: Karl Hungus |
last post by:
Is it possible to use XmlTextReader and XmlTextWriter to open an XML file,
search for a particular node, and then append nodes there?
If so, do you have a little code example (c#)?
Thanks in...
|
by: John Salerno |
last post by:
I thought I might use the XML functions in C# to help me do some
repetitive typing in an XHTML file, but I'm stuck. Here's what I have
before I just stopped:
void WriteXMLFile()
{
string path...
|
by: leonard.guillaume |
last post by:
Hi guys,
I have a task to do where I need to write an XML file into SOAP format.
I use XMLTextWriter in order to write my strings to the XML file, but I
must convert somehow this xml into SOAP....
|
by: fmancina |
last post by:
Hi,
I am employing the XmlTextWriter class to generate an XML document.
Everything works fine, until I have to write an attribute to an element
which contains a value.
Examples below:
//...
|
by: pierreuk |
last post by:
Hi All,
I have been looking at the best way of doing this but can't find a solution that doesn't involve using bytes array.
Basically I want to wrap a XmlTextWriter in a GZipStream so I produce...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |