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<string> names = 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
0
pbradley (3)
6/20/2008 8:16:52 AM
dotnet.xml 7266 articles. 0 followers. Follow

7 Replies
1137 Views

Similar Articles

[PageSpeed] 32

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/
0
mahotrash (1777)
6/20/2008 11:09:10 AM
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
0
pbradley (3)
6/20/2008 11:20:00 AM
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
0
p.bradley (2)
6/22/2008 7:21:51 PM
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
0
liderbug (2)
6/23/2008 8:44:35 PM
liderbug@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/articles/wang-whitespace.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
0
pbradley (3)
6/24/2008 8:05:27 AM
On Jun 24, 2:05 am, Peter Bradley <pbrad...@uwic.ac.uk> wrote:
> 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/articles/wang-whitespace.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 ;-)
0
liderbug (2)
6/24/2008 6:42:39 PM
Ysgrifennodd liderbug@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
0
p.bradley (2)
6/24/2008 8:07:15 PM
Reply:

Similar Artilces:

Create an ASP.NET Web Service
Not sure if this is the correct group to be posting this at but here goes. I am in the MSDN Library and doing the step-by-step instructions on the "Walkthrough: Creating a Distributed Application" and I appear to be a lost at step 5 in the section titled "To create an ASP.NET Web Service project". Line 5 says "In Solution Explorer, double-click Service1.asmx to select it". I do not see Servicece1.asmx in the Solution Explorer after following all the previous steps to the letter. In fact I don't see anything with an asmx extension. The closest thi...

XML Map
Hi all, I import XML data into a worksheet, and choose a mapping name, but I have no idea how to change the path so that it is dynamic. I've been trying to find a way to set my mapping paths to dynamic, so that when I move the folder that contains the xl file and xml files, the mapping path still works. Help :) Cheers, Grant. I'm not sure you can make it 'dynamic' per se but you can write code to change. Here's a sample of changing the bound xml document. ActiveWorkbook.XmlMaps(1).DataBinding.LoadSettings ("C:\Services Proposal.xml") -- Charles...

Creating a combination chart using cluster column & stacked bar t.
I need to create a combination chart, using cluster column and stacked bar types. I need to "cluster" two columns side by side without space in between, with stacked bars within each of these columns. Then, have space along the x axis, and have 2 more columns clustered made up of stacked bars within. I am charting 2 years side by side, with different types of data within the columns, so need to stack/segment the column. How do I create and combination chart, and how do I select these 2 types to combine together? HELP, PLEASE?!? If you stagger your data, you can create sid...

Create a calendar in excel for the next 4 yeara
How can I create a calendar in excel for the next 4 years? Begin date is October 31, 2005 and end date is October 31, 2010. -- dyukon ------------------------------------------------------------------------ dyukon's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=30062 View this thread: http://www.excelforum.com/showthread.php?threadid=497408 What form do you want the calendar to take? A very simple way is to enter your start date in cell A1 and format it as mmmm dd, yyyy. Then in cell A2, enter the formula: =A1 + 1 and ensure that this is formatted in the...

Problems XSLT Transformation of XML Data to EXCEL 2000
Does Office Excel 2000 support XSLT transformation of data from XML cause am having problem when the attachment is opened in the client side if the Excels version is in Office 2000 and also its works fine if the Office Excel Version 2002 and up when attachment file is open via browser the data is in a single line of string in the first row of the excel worksheet Glenn Gomez wrote: > Does Office Excel 2000 support XSLT transformation of data from XML cause am > having problem when the attachment is opened in the client side if the Excels > version is in Office 2000 > >...

IMF Updates and UceContentFilter.xml
When I install an IMF update, it creates a new subdirectory under the MSCFV2 directory. Because I'm using customized content filtering, my understanding is that I must manually copy my MsExchangeUceContentFilter.xml file to the new directory, and then manually run 'regsvr32' to register the new MsExchangeUceContentFilter.dll file. Has anyone written a script to automate this process? Or is Microsoft considering automating this process when a new verion of IMF is installed? -- Kevin Weilbacher [SBS-MVP] "The days pass by so quickly now, the nights are seldom long" ...

Create New Message Using Print Layout
I would like to draft new messages using "print layout" from the view menu. What I would really like to do is make that my default. Is there a way I can make "print layout" the default view when generating new messages? TIA Jerry What version of Outlook/Office and are you using Word as the editor? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. After furious head scratching, Jerry asked: | I would like to draft new messages using "...

Traversing XML with Linq to XML
Hi I am struggling to navigate an XElement and I'm not sure what is going wrong. Here's my XML via vb's xml literals Dim l_testSchema = _ <Mappings> <Definitions> <ItemGroup> <Parent>Table</Parent> <Name>Name</Name> </ItemGroup> <Item> <Parent>Column</Parent> <Name>Name</Name> &l...

Sharing a document
Using Office 2007, is there any way in which 2 (or more users) can share a document? By this I mean they both could have it open at the same time and make changes. ...

Creating forwarding rule in Exchange
Exchange 2003 SP2 If I have user fee@domain.com receiving email at address fee@domain.com, is it possible to create a rule in Exchange that does this: All emails from user@outsidedomain.com that go to fee@domain.com should be forwarded to foo@domain.com If it is possible, and I do not have a domain user named foo, would I have to create one or simply create a contact in order for the mailbox to be created? 1. You need some recipient to have the email address fee@domain.com 2. No native facility to selectively forward mail from a particular smtp address only. You could either do it usi...

my CStatic class : how to create a derived class
I want to derive a CStatic (let's call it CMyStatic) class to create a static box with a white background. So thanks to the classwizard I have done a new class derived from a CStatic and I have overidden the OnCtlColor message like this : CMyStatic::CMyStatic() { } CMyStatic::~CMyStatic() { } BEGIN_MESSAGE_MAP(CMyStatic, CStatic) //{{AFX_MSG_MAP(CMyStatic) ON_WM_CTLCOLOR() //}}AFX_MSG_MAP END_MESSAGE_MAP() //////////////////////////////////////////////////////////////////////////// / // CMyStatic message handlers HBRUSH CMyStatic::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { H...

can't create item
can't create item, when i hit a link to e mail on a internet explorer . i get the error mesge .cant create item ...

SumIf
Hi =SUMIF(A6:A2000,"(left(a6:a2000,4))=(left($K$14,4))",F6:F2000) I want to create a sub total of all values in column F, at certain subtotal cells in column F where the the first 4 (or other to be set)characters of a code in cells a6 to a2000 match the first 4 characters in cell$K$14 (or other cell to be set). The above doesn't seem to work, is it possible? am I missing something? Any help would be greatly appreciated. Ritchi Try this array* formula: =SUM(IF(LEFT(A$6:A$2000,4)=LEFT($K$14,4),F$6:F$2000,0)) * As this is an array formula, then once you have typed it in (or s...

statement.xml in HQ manager
I made some modifications to the Statement.xml receipt template (got rid of the credit limit and credit available information). Where do I go in HQ manager to recompile receipt templates, is there something similar to the process in SO manager where you go to the receipt template under registers-receipts templates in the database menu, and re-select that template file? thanks, kevin if i understand correctly, do you not have to re-compile the statement.xml file in the database like you have to for the sales receipts? i guess you must not have to because i just reprinted a statement,...

inserting documents
I have created a schedule in publisher and i want to insert into word so people can open it as an attachment because people are having trouble opening it through publisher. I had went into word and went to insert file and then tried to insert the document form publisher and it formatted all weird in like western language or something. can you please help? Save the schedule as a .jpg and insert that. -- JoAnn Paules MVP Microsoft [Publisher] Tech Editor for "Microsoft Publisher 2007 For Dummies" "Shah" <Shah@discussions.microsoft.com> wrote in message ne...

Why does Exchange create its own profiles?
I had to recreate a user's Outlook profile, and when I went into the Control Panel, Mail, there were 35 BACKUP profiles, just called BACKUP ## or Outlook. I removed them, did the work I had to do, and checked again, and another one had been created. This one user gets this every time they open Outlook. Has anyone else come across this, or have any suggestions on what to check? We use Exchange 2003. ...

Smart List Builder install documentation include on all workstati
In the documentation for Smart List Builder install it should include that it needs to be installed on all workstations that use the shared reports dictionary. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGro...

creating a function for dividing two columns
I am trying to keep track of softball stats. I trying to make a column of batting averages. I have at bats in column b, hits in column c with the results in column d. I cant get the function right so it will display the correct result. use this =SUM(C1/B1) in cell D1. Format D1 as a number with 3 decimal places. Steve Hubbard "cflan" <cflan@discussions.microsoft.com> wrote in message news:212BF952-55B9-45DF-BC8C-E8B670FA6010@microsoft.com... > I am trying to keep track of softball stats. I trying to make a column of > batting averages. I have at bats in column b,...

"Can't create the item" Solution
Hi everybody, just thought I'd share my experience with this (seemingly very common) error message (with Outlook 2003) Basically I was getting the error "Can't ceate the item" When clicking a URL in any other application (IE, Excel etc), when Outlook was open. Also I was getting the error message "Cannot start Microsoft Office Outlook. Can't create the item" when Outlook was not open. I noticed that the "Message" form was not listed in the Oulook "Standard Forms Library". I had checked that the command line for the URL:MailTo filetype was c...

How can I go to a specific page number in a large document
How do I go to a specific page number in a large word document. Read the replies to your earlier identical post -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "yisaajao" <yisaajao@discussions.microsoft.com> wrote in message news:CFC4289D-FC93-4C1B-951B-DB08CED833...

Creating an index 04-27-10
-- I have been attempting to create an index using Microsoft Word 2007. I have a document that includes 5 separate Word files (chapters 1-5). Total pages of these 5 chapters is close to 800. Is there a way to create an index that will pull automarked entries from each file and allow me to incorporate into a separate index document, including updating as needed (much like the automated TOC)? Any assistance is much appreciated. VLBarnes You can do this with an RD field. See “Creating a Table of Contents Spanning Multiple Documents” at http://pubs.logicalexpressions.com/Pub0...

Need help with updating XML file
Hi, I am using an xml bound to a datalist to display photos in a gallery. XML file is generated and then bound to the datalist. What i want to do is edit the captions for the photos by clicking Edit in the datalist and then update. My file looks like the snippet below. For example i want to just update the caption for the first photo. Any help is greatly appreciated. XML is not my forte. <Photos> <Photo> <PhotoID>1</PhotoID> <Caption></Caption> <FileName>DSC00067.jpg</FileName> <FilePath>~/photos/Stills/DSC00067.jpg</FilePath&g...

Using tables created in 2003 IN 2007
My office has recently upgraded to 2007. I enjoy new features such as the ability to highlight a few words within the table without the ENTIRE table's font changing; unfortunately, this only works in tables I have created since the upgrade. My old tables that were brought over from 2003 do not have this capability. Is there an add-on out there? I do not have to resort to re-typing and creating all new tables. PS. Copy and pasting into a new table does not work. Convertting the file using the office button does not work. Help? please? I think you talking about what is called...

how do i open a publisher file created in new version?
I get publisher files in new versions of publisher. I have publisher 2000. I can't open these files but don't want to update publisher. Is there a download program I can get to translate these files? "Peg" <Peg@discussions.microsoft.com> wrote in message news:4BD8AEDC-8386-4E7B-9D12-DAF429B171A2@microsoft.com... >I get publisher files in new versions of publisher. I have publisher 2000. > I can't open these files but don't want to update publisher. Is there a > download program I can get to translate these files? There is not a download to tra...

Creating a chart to convert hundredths to minutes
My company is using a manual hundredths to minutes chart to change decimals to minutes. Example if the hours worked shows as 1.83, the .83 is converted to :50 minutes. I am using a formula to calculate hours worked for the AM and PM routes with a sign on and sign off time for each. The formula looks like this =(D11-C11)*24 Sign on time is 5:20-C11, sign off time is 9:25 D11, hours =4.08 The .08 in hundredths =05 minutes. At one point I use this formula to display 4.08 in h:mm format, =TEXT(D11-C11,"h:mm") This returns 4:05. Is there a way to create a lookup table that contains...