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

Creating an XML document

Hi,

First of all, a confession. This is a cross post from the
microsoft.public.dotnet.general list. I posted there not realising that
this list existed. Apologies to those who read both lists. I'll do my
best to prevent two separate conversations developing.

I'm trying to create an XML Document. This is what I want to end up with:

<?xml version="1.0" encoding="UTF-8" ?>
<epp xmlns="urn:iana:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:iana:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<check>
<domain:check xmlns:domain="urn:iana:xml:ns:domain-1.0"

xsi:schemaLocation="urn:iana:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:name>example1.tld</domain:name>
<domain:name>example2.tld</domain:name>
<domain:name>example3.tld</domain:name>
</domain:check>
</check>
<unspec/>
<clTRID>ABC-12346</clTRID>
</command>
</epp>

I've tried coding this in all sorts of ways, but I just can't get the
namespaces correct.

Here's some of my code as it currently stands.

This code creates the basic skeleton of the document:

public Hashtable Check(string domain, string[] extensions)
{
// Create the list of fully qualified domain names
List<stringnames = new List<string>();

for (int i = 0; i < extensions.Length; i++)
{
names.Add(domain + extensions[i]);
}

byte[] bytes = GetXmlSkeleton();

At this point I have the basic skeleton as an array of bytes, which I
then convert to a string to give me:

<?xml version="1.0" encoding="UTF-8" ?>
<epp />

I then load the string into an XmlDocument like this:

XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
XmlNode root = doc.DocumentElement;
This is where it all falls apart. I've tried all sorts of ways of
getting the namespaces correct, but nothing seems to work. At the
moment, this is what I have:
XmlNamespaceManager manager = new XmlNamespaceManager(doc.NameTable);
manager.AddNamespace("xsi",
"http://www.w3.org/2001/XMLSchema-instance");
manager.AddNamespace("schemaLocation", "urn:iana:xml:ns:epp-1.0
epp-1.0.xsd");
manager.AddNamespace("domain", "urn:iana:xml:ns:domain-1.0");

doc.DocumentElement.SetAttribute("xmlns", "urn:iana:xml:ns:epp-1.0");
doc.DocumentElement.SetAttribute("xsi", "xmlns",
"http://www.w3.org/2001/XMLSchema-instance");
doc.DocumentElement.SetAttribute("schemaLocation", "xsi",
"urn:iana:xml:ns:epp-1.0 epp-1.0.xsd");

XmlElement aNode = doc.CreateElement("command");
root.AppendChild(aNode);

XmlElement checkNode = doc.CreateElement("check");
aNode.AppendChild(checkNode);

aNode = doc.CreateElement("domain", "check",
"urn:iana:xml:ns:domain-1.0");
aNode.SetAttribute("schemaLocation", "xsi",
"urn:iana:xml:ns:domain-1.0 domain-1.0.xsd");
checkNode.AppendChild(aNode);

XmlElement innerNode = null;
XmlText textNode = null;

for (int i = 0; i < extensions.Length; i++)
{
innerNode = doc.CreateElement("domain", "name",
"urn:ietf:params:xml:ns:obj");
aNode.AppendChild(innerNode);
textNode = doc.CreateTextNode("domain:name");
textNode.Value = domain + extensions[i];
innerNode.AppendChild(textNode);
}

This creates all the nodes correctly, including the text nodes, but the
namespaces are all over the place.

Any help would be very gratefully received. I certainly have a bit less
hair tonight than I started out with this morning.

Thanks
Peter
Jun 27 '08 #1
7 1543
Peter Bradley wrote:
I'm trying to create an XML Document. This is what I want to end up with:

<?xml version="1.0" encoding="UTF-8" ?>
<epp xmlns="urn:iana:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:iana:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<check>
<domain:check xmlns:domain="urn:iana:xml:ns:domain-1.0"

xsi:schemaLocation="urn:iana:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:name>example1.tld</domain:name>
<domain:name>example2.tld</domain:name>
<domain:name>example3.tld</domain:name>
</domain:check>
</check>
<unspec/>
<clTRID>ABC-12346</clTRID>
</command>
</epp>
<?xml version="1.0" encoding="UTF-8" ?>
<epp />

I then load the string into an XmlDocument like this:

XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
XmlNode root = doc.DocumentElement;
That is the wrong approach, the namespace of an element of attribute
node is determined when you create it and not by later adding namespace
declarations.
So you need e.g.
const string epp = "urn:iana:xml:ns:epp-1.0";
const string xsi = "http://www.w3.org/2001/XMLSchema-instance";
const string domain = "urn:iana:xml:ns:domain-1.0";

XmlDocument doc = new XmlDocument();
XmlElement eppEl = doc.CreateElement("epp", epp);
doc.AppendChild(eppEl);

XmlAttribute schemaLocation = doc.CreateAttribute("xsi",
"schemaLocation", xsi);
schemaLocation.Value = "urn:iana:xml:ns:epp-1.0 epp-1.0.xsd";
eppEl.SetAttributeNode(schemaLocation);

XmlElement command = doc.CreateElement("command", epp);
eppEl.AppendChild(command);

XmlElement check = doc.CreateElement("check", epp);
command.AppendChild(check);

XmlElement dCheck = doc.CreateElement("domain", "check",
domain);
command.AppendChild(dCheck);

and so on where you make sure you pass the namespace URI an element or
attribute belongs to to the CreateElement or CreateAttribute method.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
Martin Honnen wrote:
Peter Bradley wrote:
<snip />
That is the wrong approach, the namespace of an element of attribute
node is determined when you create it and not by later adding namespace
declarations.
Yes. In my heart of hearts I knew it must be :)
So you need e.g.
< ... >

and so on where you make sure you pass the namespace URI an element or
attribute belongs to to the CreateElement or CreateAttribute method.

I'll give that a go and let you know how I get on - although it may be
Monday before I'm able to do that.

My grateful thanks. This has been driving me nuts. Or, perhaps, *more*
nuts.

Cheers
Peter
Jun 27 '08 #3
Ysgrifennodd Martin Honnen:
That is the wrong approach, the namespace of an element of attribute
node is determined when you create it and not by later adding namespace
declarations.
So you need e.g.
const string epp = "urn:iana:xml:ns:epp-1.0";
const string xsi = "http://www.w3.org/2001/XMLSchema-instance";
const string domain = "urn:iana:xml:ns:domain-1.0";

XmlDocument doc = new XmlDocument();
XmlElement eppEl = doc.CreateElement("epp", epp);
doc.AppendChild(eppEl);

XmlAttribute schemaLocation = doc.CreateAttribute("xsi",
"schemaLocation", xsi);
schemaLocation.Value = "urn:iana:xml:ns:epp-1.0 epp-1.0.xsd";
eppEl.SetAttributeNode(schemaLocation);

XmlElement command = doc.CreateElement("command", epp);
eppEl.AppendChild(command);

XmlElement check = doc.CreateElement("check", epp);
command.AppendChild(check);

XmlElement dCheck = doc.CreateElement("domain", "check",
domain);
command.AppendChild(dCheck);

and so on where you make sure you pass the namespace URI an element or
attribute belongs to to the CreateElement or CreateAttribute method.

Brilliant, Martin. Thanks.

All working, now.

Cheers
Peter
Jun 27 '08 #4

This is the closest post I've found to date - so I'll ask you folks.
A question of formatting (which I can't find anywhere).
In a vxml file I have the line(s):

<log label=abc>
Now is the time
</log>

which turns out to be different than:

<log label=abc>Now is the time</log>

The first example goes in as "... time[newline]" whereas the second
goes in as "...time" (no CR)

or should it be "Now is the time" (quotes)? Is there a xml
formating document?

Thanks
Jun 27 '08 #5
li******@gmail.com wrote:
This is the closest post I've found to date - so I'll ask you folks.
A question of formatting (which I can't find anywhere).
In a vxml file I have the line(s):

<log label=abc>
Now is the time
</log>

which turns out to be different than:

<log label=abc>Now is the time</log>

The first example goes in as "... time[newline]" whereas the second
goes in as "...time" (no CR)

or should it be "Now is the time" (quotes)? Is there a xml
formating document?

Thanks

Does this help?

http://www.oracle.com/technology/pub...hitespace.html

I'm assuming it's the way that your DTD/schema specifies that white
space is treated. I know nothing at all about vxml, so if I've
completely missed the point, my apologies.

Cheers

Peter
Jun 27 '08 #6
On Jun 24, 2:05 am, Peter Bradley <pbrad...@uwic.ac.ukwrote:
lider...@gmail.com wrote:
This is the closest post I've found to date - so I'll ask you folks.
A question of formatting (which I can't find anywhere).
In a vxml file I have the line(s):
<log label=abc>
Now is the time
</log>
which turns out to be different than:
<log label=abc>Now is the time</log>
The first example goes in as "... time[newline]" whereas the second
goes in as "...time" (no CR)
or should it be "Now is the time" (quotes)? Is there a xml
formating document?
Thanks

Does this help?

http://www.oracle.com/technology/pub...hitespace.html

I'm assuming it's the way that your DTD/schema specifies that white
space is treated. I know nothing at all about vxml, so if I've
completely missed the point, my apologies.

Cheers

Peter
Your oracle.com page was just what I was looking for - many thanks.
And from my vasssssst experience I'd wag that xml and vxml would be
the same except for what they end up doing. So I expect the rules to
be the same - format wise.
av a beer on me ;-)
Jun 27 '08 #7
Ysgrifennodd li******@gmail.com:
>Peter

Your oracle.com page was just what I was looking for - many thanks.
And from my vasssssst experience I'd wag that xml and vxml would be
the same except for what they end up doing. So I expect the rules to
be the same - format wise.
av a beer on me ;-)

I'll do that, although I'd have to point out at the same time that I
just got lucky.

:)
Peter
Jun 27 '08 #8

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

Similar topics

6
by: Kerri McDonald | last post by:
We have an application where the user fills out many screens and when they are done, we are supposed to display the text they entered in a word or excel format. That is fairly easily accomplished...
20
by: svend | last post by:
I'm messing with some code here... Lets say I have this array: a1 = ; And I apply slice(0) on it, to create a copy: a2 = a1.slice(0); But this isn't a true copy. If I go a1 = 42, and then...
7
by: Russ | last post by:
Hi All, I have a problem getting the following simple example of "document.write" creating a script on the fly to work in all html browsers. It works in I.E., Firefox, and Netscape 7 above. It...
2
by: pshvarts | last post by:
(I'm new in SOAP) I get some wsdl file (from apache service ). I tried creating SOAP client with .NET - trying to add Web Reference and get error like: "Custom tool error: Unable to import...
6
by: Adam Tilghman | last post by:
Hi all, I have found that IE doesn't seem to respect the <SELECT> "multiple" attribute when set using DOM methods, although the attribute/property seems to exist and is updated properly. Those...
5
by: sam | last post by:
Hi all, I am dynamically creating a table rows and inerting radio buttons which are also dynamically created. Everything works fine in Firefox as expected. But I am not able to select radio...
4
by: GRenard | last post by:
Hi, I'm trying just to display a table on a webpage using DOM elements created dynamically. I really don't understand why IE doesn't display the document successfully... If I make a...
3
by: patrickkellogg | last post by:
I have this code when you click the buttom is suppose to add a job history. it works with firefox, opera, but not ie. (please note - new entries don't have all the elements in them yet, but...
1
by: skyson2ye | last post by:
Hi, guys: I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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...
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.