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
895 Views

Similar Articles

[PageSpeed] 4

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 (1778)
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 a roster
How can you create a weekly roster in which functions can be assigned to more than 10 people. The roster should be updatable, so that when holidays and days off are marked on the weekly roster they will be taken account of it future rosters. ...

Automatic Appling AR documents
- I'm looking for a routine that can be scheduled to run through all unapplied payments and auto-apply them for all customers within a GP10 Company. Any/all assistance is appreciated. Thanks Jon Jon, I believe the Microsoft Professional Services team has a tool for sale that will do this. Your GP Partner should be able to help you with details and pricing on this. -- Victoria Yudin Dynamics GP MVP Want to use Crystal Reports with GP? http://www.flex-solutions.com/gpreports.html blog: http://www.victoriayudin.com "JColesby" <jcolesby@gmail.com>...

importing or creating reference footnotes
I am trying to import a word document into publisher and it has reference footnotes within the document. The reference footnotes are not coming into the publisher document with the reference footnotes. Correct, they will not up to Publisher 2003. In Publisher 2003 depending on which version of Word you are using if they will or not. -- "If you don't know where you are going, any road will take you there!" ...

Generating a document from Opportunity
Opportunities for us are the center of the sales cycle. What is the "best practices" solution to create a document that is launched from an Opportunity that pulls in the relevant data of the Company name and address, and stock and custom Opportunity fields? In a perfect world it would automatically post an activity in the Opp's history and attach the said merged document to that activity. Any thoughts or direction, much appreciated. Rich Scott Hi, Richard. I have the same question. I actually wonder what are the "best practices" for creating a document from a...

Mailbox not created when AD account created
A couple of days ago I noticed that I created a user account but the 'Email Addresses' tab of the user properies did not list any email addresses. Subsequent new user accounts have all experienced the same. I researched the knowledge and tried the recommended solutions to either manaully start the recipient update service or rebuild te recipient update service. Neither recommendation has resulted in a mailbox being created for this particular user or any additional user that I have created since this error first showed up. I performed a Windows update last Thursday and so I bel...

xml schema, order unimportant
I've got some xml that looks like this: <root> <name></name> <id></id> <section> <question></question> <question></question> </section> <section> <question></question> </section> </root> name and id must appear and my appear in any order section may appear 0 or more times, question may appear 0 or more times. I use a choice group with maxOccurs= unbounded so that the elements could appear in any order. My problem is that now each element can a...

VLookup in other document
Here is my problem. Please help I have two documents A and B. In document A I have a table existing of codes and descriptions Range A1: B100 Column A contains codes, Column B contains descriptions In document B I want to lookup the description for a given code. I have a cell C10 containing the code and a cell C11 containing a formula =VLOOKUP(A1;'K:\Douane\Regressie\[RTScenario.xls]FxP'!$A$1:$B200;2) Till so far it works !! But I use this formula many times in my excel sheet and in many Excel documents, so if Ithe lokation of document A changes, I have to change all the for...

Task Create - Status
I'm trying to make a simple task, when a user owner is assigned a task in CRM, it receives an email letting it know it has one. I have the following below, but it is not generating one when i assign one manually in the CRM. What to do? I've tried both the following: When task is created E-Mail to:[owner];Subject test As well as: When task is created if Task activity status = Open then E-Mail to:[owner];Subject test I've checked the mailserver many times over, and I can send emails manually from the CRM so you can rule that out Tested out ok on our end. Some ideas:...

Help Creating XmlNode / XmlAttribute Elegantly
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString" value="server=(local);" /> </appSettings> </configuration> I am using a XmlDocument for my base implementation. I am looking to see if there is a better way to add a new node / attribute than using XmlDocument.InnerXml. I would consider this to be a hack but couldn't really see another way of doing this without definin...

Convert two separate Word documents into one
Anybody know how to merge/convert two separate (one page) Word document into one (two page) document? HELP> In news:B5526982-84F0-4552-A34F-7F72AB3DADDC@microsoft.com, CAOWEN <CAOWEN@discussions.microsoft.com> typed: > Anybody know how to merge/convert two separate (one page) Word > document into one (two page) document? > > HELP> Open one of them. PUt the cursor at the very bottom (CTRL-END keys works well for that). Click Insert File. Save the resulting combined file to a NEW NAME to avoid losing either of the two originals. HTH, Twayne ...

Create external database
Hi all. I need to create an external database (file). On a site I found this code: ------------------------------------------------------ Function CreateLinkedExternalTable(strTargetDB As String, strProviderString As String, strSourceTbl As String, strLinkTblName As String) As String 'strTargetDB = Source Database Name 'strProviderString = Not used, currently hard coded 'strSourceTbl = Source Table name in the database we are linking too. 'strLinkTblName = Table name we would like to see in the Access Database. Dim catDB As ADOX.Catalog Dim tblLink As...

How to create pie chart with %
I have got a problem that I don't if excel could help me to calculate the % within a column and draw a pie chart. My case is I have a column containing a series of numbers. e.g. 1,4,8,1,3,9,11,2,4,5,6,.........etc I want to draw a pie chart that showing 1-3 , 4-6, 7-9, >9 with the corresponding % inside that column. Can anyone tell me how can I make it ? Ray - You need to calculate the frequencies in your data. Let's assume your data is in A1:A12. In B1:B3 enter these numbers, the upper limits on the groupings: 3 6 9 You can enter ">9" into B4 witho...

How can I use strikethrough in a Publisher 2007 document?
I want to use strikethrough on some text within a textbox in a Publisher 2007 document, but I cannot find that option under formatting font. Under the Edit tab, I see "Edit Story Using Microsoft Word" and this takes me to a screen where I can get at the MSWord strikethrough formatting, but when I close that window, the strikethrough disappears. The only way to have strikethrough in Publisher is to select the line tool and draw a line through the text. -- Don Vancouver, USA "JoAnn" <JoAnn@discussions.microsoft.com> wrote in message news:49640...

Newbie: Return a xml-document to client
Hi I have a webservice that generates a xmldocument when you call it either from a .aspx-site or with http-GET. eg. http://...ws.asmx/method?arg1&arg2 I now want to present this xmldocument for the user i his/her webclient (eg Internet Explorer). I cannot return the xml-document as a dataset since " The same table (ContactAddress) cannot be the child table in two nested relations. at System.Data.DataRelation.CheckNestedRelations() " A problem with the datasets. Hence my xmldocument isn�t compatible with a dataset. My question is how i should solve this problem. I can retur...

Email address not created when a new user is created
All, This issue recently happened in my company. Upon creating a new user, the policy was set to create the smtp and X400 address automaticaly. Now when we create a user the smtp and x400 addresses are not created, and when attempting to setup the new user in outlook, the address cant be found. We are using exchange 2003 SP1 on Win2k3 servers. On Wed, 13 Jul 2005 06:49:07 -0700, "Bryan" <Bryan@discussions.microsoft.com> wrote: >All, >This issue recently happened in my company. Upon creating a new user, the >policy was set to create the smtp and X400 addres...

Exchange 2010 MRM, no log files being created
I'm hoping someone can help me with this issue....it has been driving me crazy for days. I have enabled MRM logging on our exchange server, and I can see that some of the policies are working when I run start-managedfolderassistant. We have a retention policy tag on the deleteditems folder, and this does work. The problem is I am not getting any files in the MRM log directory. C:\Program Files\Microsoft\Exchange Server\V14\Logging\Managed Folder Assistant Events 9021 and 9022 are logged in the Application log, but where are the files? Below is the output of my mai...

when form created
I have a form which was created by someone else (not a form template) which is like a questionnaire with empty boxes to be completed. When the boxes are typed in all the margins move to accommodate the words being typed. Is there a way to fix/lock the original form and then just fill in the blank boxes? I suspect this is set up as a table with auto resizing enabled. Displaying table gridlines (Table | Show Gridlines) will help you see what you're dealing with. Then select the table, go to the Table tab of Table Properties, click Options, and clear the check box for "A...

XML DOM question
Hi All, I use XML DOM to read and write XML files. I did not find any specification whether or not XML DOM locks files for reading and writing at the moment it reads or writes to the file. I have a system where different applications can read and write from and to XML files using XML DOM, so it is important to me to know whether or not the file that is being read is locked for writing and vice versa. Does anybody can help me with this issue or refer to a proper article? Thanks a lot in advance. -- Mark. How about singlenton pattern in your situation? We can't use singlenton th...

Can't open excel documents
When I try to open an excel doc is 'stalls' ... getting stuck on 'virus scan' dialouge at the bottom of the sheet. I can open excel w/o a file and save one, but when I try opening an existing one, Excel simply won't do it and I eventually have to contl.alt.del. it in order to continue. Any ideas? ...

Creating a Brochure
How do you create a 3-column brochure from scratch for Publisher 2002? I can only find the directions for the 2003 version. Quick help would be appreciated, project is due Monday. Create a three-panel or four-panel folded publication http://office.microsoft.com/en-us/assistance/HP011646681033.aspx Scroll down to the section that says "Build a three-panel or four-panel publications from scratch." -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Derek" <Derek@discussions.microsoft.com> wrote in message news...

Users mailboxes not created when user created
I have a problem that recently just started happening on my exchange 2003 server. When i create a new user account and create the mailbox for exchange, once im done, the mailbox isnt created, adn if you go into the properties of the user account adn go to the exchange email address tab, there isnt an smtp or an x.400 address listed. I am having to manually create and add these, adn then go delete the exchange mailbox and recreate it. This is really annoying and would love to know if anyone has any ideas of how to fix it. Thanks Jason In news:9F836A43-98BF-435A-AA43-AFF10124BE3F@micro...

Protection of document properties ..??
OK, not sure if this is possible but here goes ... I have created a master document in Excel, this will be used by hundreds of people, they will be changing the information within the document but what I need to do is protect the settings of the document e.g. the page setup, whilst still letting changes to the information contained within the document itself. Is there anyway of doing this ? Cheers. Password protect the entire document, then unprotect the user data areas ....? If users need to print off specific bits of it for their own use, create interdependant user pages including jus...

How to create Access macro shortcut
I'm still using Access 97 and saw something the other day that I would like to use that was in Access 2000. In an Access 2000 database, there was a .mam file in a directory that launched the Access 2000 program and ran a macro. How do you set this up? Can it be done in Access 97? If so, how? Hi. > How do you set this up? Select the macro in the Database Window and right click with your mouse, then select "Create Shortcut..." in the pop-up menu. Follow the prompts for where to place the shortcut and what to name it. The default is: <PathToDeskTopDir>\Shortcut ...

CRM should let me create custom fields in batch
Hi, With MS CRM v3.0, when we have a group of fields to create, it would be faster to be able to enter the list and then submit the list for processing. Thank you. Felix. ---------------- 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/C...

Creating an ad book
How do I divide a page into equal sections (halves, qarters, eights)? I need to scan and type ads and coupons into this booklet. New at this. After managing to set up OE-QuoteFix on his new PC, Ed reads a message from FRSH <anonymous@discussions.microsoft.com>... > How do I divide a page into equal sections (halves, qarters, eights)? Arrange > Layout Guides > Grid Guides -- Ed Bennett - MVP Microsoft Publisher http://www.mvps.org/the_nerd/ Before reading this message, view the disclaimer: http://mvps.org/the_nerd/disclaim.htm ...