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

Creating an XML Document

Hi,

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

<pre>

<?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>

</pre>

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:

<code>

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();

</code>

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:

<code>

XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
XmlNode root = doc.DocumentElement;

</code>

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:

<code>

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);
}

</code>

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
1 988
Peter Bradley wrote:
Hi,

I'm trying to create an XML Document.
<snip />

I've received a reply to this from the dotnet.xml list. I posted there
after posting here in ignorance of the existence of the xml list.

So apologies for x-posting.

Cheers

Peter
Jun 27 '08 #2

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: 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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.