473,386 Members | 1,610 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,386 software developers and data experts.

More than one attribute.

you can write
writer.WriteStartElement("data", "http://www.w3.org/1999/XMLSchema-instance");

in your code for,

<data xmlns="http://www.w3.org/1999/XMLSchema-instance">

how do you write,

<data xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../documents/xml/epic.xsd">

for two attributes?
Jun 27 '08 #1
3 2483
Dave wrote:
you can write
writer.WriteStartElement("data", "http://www.w3.org/1999/XMLSchema-instance");

in your code for,

<data xmlns="http://www.w3.org/1999/XMLSchema-instance">

how do you write,

<data xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../documents/xml/epic.xsd">

for two attributes?
Note that the official W3C schema instance URI is
http://www.w3.org/2001/XMLSchema-instance.

As for writing attributes, in case of a namespace declaration like
xmlns:xsi="..." you don't need to write it at all, it suffices to write
the attribute in that namespace:
const string xsi = "http://www.w3.org/2001/XMLSchema-instance";
using (XmlWriter writer = XmlWriter.Create(Console.Out))
{
writer.WriteStartElement("data");
writer.WriteAttributeString("xsi",
"noNamespaceSchemaLocation", xsi, "../documents/xml/epic.xsd");
writer.WriteEndElement();
}

If you want to explicitly write the namespace declaration, then that is
possible too:

const string xsi = "http://www.w3.org/2001/XMLSchema-instance";
using (XmlWriter writer = XmlWriter.Create(Console.Out))
{
writer.WriteStartElement("data");
writer.WriteAttributeString("xmlns", "xsi",
"http://www.w3.org/2000/xmlns/", xsi);
writer.WriteAttributeString("xsi",
"noNamespaceSchemaLocation", xsi, "../documents/xml/epic.xsd");
writer.WriteEndElement();
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
Thanks, that exactly what I needed.

One more question, the customer where we're sending the files to says they
can't read double quotes around attributes, is there a way to specify single
quotes?

"Martin Honnen" wrote:
Dave wrote:
you can write
writer.WriteStartElement("data", "http://www.w3.org/1999/XMLSchema-instance");

in your code for,

<data xmlns="http://www.w3.org/1999/XMLSchema-instance">

how do you write,

<data xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../documents/xml/epic.xsd">

for two attributes?

Note that the official W3C schema instance URI is
http://www.w3.org/2001/XMLSchema-instance.

As for writing attributes, in case of a namespace declaration like
xmlns:xsi="..." you don't need to write it at all, it suffices to write
the attribute in that namespace:
const string xsi = "http://www.w3.org/2001/XMLSchema-instance";
using (XmlWriter writer = XmlWriter.Create(Console.Out))
{
writer.WriteStartElement("data");
writer.WriteAttributeString("xsi",
"noNamespaceSchemaLocation", xsi, "../documents/xml/epic.xsd");
writer.WriteEndElement();
}

If you want to explicitly write the namespace declaration, then that is
possible too:

const string xsi = "http://www.w3.org/2001/XMLSchema-instance";
using (XmlWriter writer = XmlWriter.Create(Console.Out))
{
writer.WriteStartElement("data");
writer.WriteAttributeString("xmlns", "xsi",
"http://www.w3.org/2000/xmlns/", xsi);
writer.WriteAttributeString("xsi",
"noNamespaceSchemaLocation", xsi, "../documents/xml/epic.xsd");
writer.WriteEndElement();
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #3
Dave wrote:
One more question, the customer where we're sending the files to says they
can't read double quotes around attributes, is there a way to specify single
quotes?
XML allows both double and single quotes, if you have agreed to exchange
XML then whoever consumes that should be able to deal with double quotes.

If you really want to change that then you will need to use
XmlTextWriter and set its QuoteChar property as needed:
XmlTextWriter writer = new XmlTextWriter("file.xml", Encoding.UTF8);
writer.QuoteChar = '\'';

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #4

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

Similar topics

6
by: R.Wieser | last post by:
Hello All, I'm trying to get a "Virtual Listbox" to work. I've currently got a form, and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and LBS_NODATA flags on it. I've...
2
by: kj | last post by:
In an earlier thread, JKrugman posted the following quote: > ...the purpose of XML namespaces is to uniquely identify element > and attribute names. Unprefixed attribute names can be uniquely...
40
by: Greg G | last post by:
http://risky-biz.com/new/risky.html I finally got DSL service recently, but I haven't forgotten the agony of waiting for the 64th image to load before I can see ANYTHING on a page. So I will...
9
by: Lilith | last post by:
I was working on a routine that requires me to parse out a list of attributes of an object in a text line. An attribute could be empty, causing it to revert to it's current value, or the list of...
2
by: chris.millar | last post by:
The class below uses the switch clause in the GetXSLT method. I want it to code it with a more OO approach does anyone have any suggestions, or change to make. cheers using System; using...
1
by: Kai Huener | last post by:
ello, I try to make a function, adding automatically all functions to a new class which are necessary because of implemented Interfaces or inherited, abstract classes. In the last case, it is...
10
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and...
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
0
by: xirowei | last post by:
I try to search information from many websites, but what i can found is they only demonstrate the example with ONE ATTRIBUTE in a Cookie only. What i want is how to set more than 1 attribute in a...
6
by: WT | last post by:
Hello, Using url rewritting and ajax.net, I tried to circumvent some potential problems with postback url using a code from a sample given by Scott. The idea is to use a control Adapter on...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.