473,395 Members | 2,446 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,395 software developers and data experts.

Output XML file using XElement

I am writing a XML file suing XElement. How can I output a file like
the following? I got an exception if if I use ':' in the element name
or attribute name.

Thanks,

<?xml version="1.0" encoding="UTF-8"?>
<epoStick out tongueolicySchema xmlns:epo="epo-policy"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</epoStick out tongueolicySchema>
Sep 11 '08 #1
4 4985
On Thu, 11 Sep 2008 10:42:09 -0700, standerby <st*******@yahoo.comwrote:
I am writing a XML file suing XElement. How can I output a file like
the following? I got an exception if if I use ':' in the element name
or attribute name.
What is the code you're trying to use? It's hard to say what you're doing
wrong if you don't say what you're doing.

If I've read the docs correctly, you should be able to create a proper
XName instance by combining an XNamespace instance with a string:

XNamespace ns = "xmlns";
XName nameEpo = ns + "epo",
nameXsi = ns + "xsi";

Then you'd pass the appropriate XName to the XElement.SetAttribute()
method (or just create the XName in the method call itself, rather than
putting it in a variable).

If that doesn't address your question, you should probably be more
specific. :)

Pete
Sep 11 '08 #2
On Sep 11, 2:22*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Thu, 11 Sep 2008 10:42:09 -0700, standerby <stande...@yahoo.comwrote:
I am writing a XML file suing XElement. How can I output a file like
the following? I got an exception if if I use ':' in the element name
or attribute name.

What is the code you're trying to use? *It's hard to say what you're doing *
wrong if you don't say what you're doing.

If I've read the docs correctly, you should be able to create a proper *
XName instance by combining an XNamespace instance with a string:

* * *XNamespace ns = "xmlns";
* * *XName nameEpo = ns + "epo",
* * * * *nameXsi = ns + "xsi";

Then you'd pass the appropriate XName to the XElement.SetAttribute() *
method (or just create the XName in the method call itself, rather than *
putting it in a variable).

If that doesn't address your question, you should probably be more *
specific. *:)

Pete
Pete,
I have tried similar code to yours before I post here and it doesn't
work very well. Your code will output like this
<EPOPolicySchema p1:epo="mcafee-epo-policy" p1:xsi="http://www.w3.org/
2001/XMLSchema-instance" xmlns:p1="xlmns">
What I need is the exact format like <epo:EPOPolicySchema
xmlns:epo="mcafee-epo-policy" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"because it is vendor specific format. Do you know
how to make change? Thanks.
Sep 11 '08 #3
On Thu, 11 Sep 2008 11:39:43 -0700, standerby <st*******@yahoo.comwrote:
I have tried similar code to yours before I post here and it doesn't
work very well. Your code will output like this
<EPOPolicySchema p1:epo="mcafee-epo-policy" p1:xsi="http://www.w3.org/
2001/XMLSchema-instance" xmlns:p1="xlmns">
What I need is the exact format like <epo:EPOPolicySchema
xmlns:epo="mcafee-epo-policy" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"because it is vendor specific format. Do you know
how to make change? Thanks.
No, I don't. I didn't realize that's what XElement would output. If
that's really what it does, I'd report a bug to Microsoft (at
http://connect.microsoft.com/). That seems unnecessarily complicated.

But, you still haven't posted a concise-but-complete code demonstrating
what you've tried, so it's difficult for anyone to provide an accurate
answer.

Pete
Sep 11 '08 #4
standerby wrote:
I am writing a XML file suing XElement. How can I output a file like
the following? I got an exception if if I use ':' in the element name
or attribute name.

Thanks,

<?xml version="1.0" encoding="UTF-8"?>
<epoStick out tongueolicySchema xmlns:epo="epo-policy"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</epoStick out tongueolicySchema>
Stick out tongue, eh? :-)

XNamespace epo = "mcafee-epo-policy";
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XElement epoPolicySchema = new XElement(epo + "EPOPolicySchema",
new XAttribute(XNamespace.Xmlns + "epo", epo.NamespaceName),
new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName)
);

This is not terribly elegant or intuitive, but then, neither are XML namespaces.

--
J.
Sep 11 '08 #5

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

Similar topics

9
by: Stefan Mueller | last post by:
I'd like to set a variable called 'FocusIsOn' if a button got the focus. Because my button is dynamically created I do it like xelement = document.createElement("input") xelement.type = "button"...
6
by: Alec MacLean | last post by:
Hi, I've created a small application for our company extranet (staff bulletins) that outputs a list of links to PDF's that are stored in a SQL table. The user clicks a link and the PDF is...
0
by: coldboyqn | last post by:
Hi you guy! I am using Visual Web Express 2008 to design a server controls (a component). The control is almost very simple. protected override void RenderContents(HtmlTextWriter writer)...
2
by: huwfriedhoff | last post by:
Hi Guys, I have a friend who is developing a dvd store in Visual basic ( It's a WPF application) and stores the data in an XML file. the content of the XML look like this: <DVDInfo> <DVD>...
4
by: Rory Becker | last post by:
Is there a way to do something like the following... ------------------------------------------------------------- Dim x As String =...
11
by: Michael Bray | last post by:
I'm playing around with XElement stuff, and I've come across a difficulty. The XML document that I'm reading contains an xmlns declaration on the main node... <root xmlns="http://www.me.com">...
12
by: G.S. | last post by:
Is it acceptable to use { } blocks to improve readability and maintainability of the code? Example: //add the checkbox column DataGridViewCheckBoxColumn column = new...
5
by: TompIfe | last post by:
Hi, I have a web service that reads data from an Access database using datareader and place the data in an array that the web method returns. Now, I want to make the web service also to return an...
5
by: Edwin | last post by:
I am trying to write an application among which one of the functions is to determine the number of unique extensions found in a directory and all of its sub directories. I am trying to use Linq to...
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...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.