xmlns="" attribute on child node

I'm using IXmlDocument to write an XML file.
The node "leveranse" automatically get a xmlns attribute that is empty.
How can I avoid/remove this?

Here is my code and result:

    XML := NewXMLDocument;
    XML.Encoding := 'utf-8';
    XML.Options := [doNodeAutoIndent];

    root := XML.AddChild('melding');
    root.Attributes['xmlns'] := 'urn:ske:fastsetting:innsamling:slakt:2.0';
    root.Attributes['xmlns:xsi'] := 'http://www.w3.org/2001/XMLSchema-instance';
    root.Attributes['xsi:schemaLocation'] := '"urn:ske:fastsetting:innsamling:slakt:2.0 slakt2.0.xsd"';

    leveranse:= root.AddChild('leveranse');

    oppgaveGiver:= leveranse.AddChild('oppgavegiver');
    orgNr:=  oppgaveGiver.AddChild('organisasjonsnummer');
    orgNr.Text:= '123456789';
    orgNavn:= oppgaveGiver.AddChild('organisasjonsnavn');
    orgNavn.Text:= 'Company';

    inntektsAar:= leveranse.AddChild('inntektsaar');
    inntektsAar.Text:= FormatDateTime('yyyy', Now);
    levRef:= leveranse.AddChild('oppgavegiversLeveranseReferanse');
    levRef.Text:= IntToStr(LeveranseNr);
    levType:= leveranse.AddChild('leveransetype');
    levType.Text:= 'Ordinær';

    kontaktInfo:= oppgaveGiver.AddChild('kontaktinformasjon');
    navn:=  kontaktInfo.AddChild('navn');
    navn.Text:= 'Petter';
    tlf:=  kontaktInfo.AddChild('telefonnummer');
    tlf.Text:= '99887766';
    epost:=  kontaktInfo.AddChild('varselEpostadresse');
    epost.Text:= 'petter@mailserver.no';
    sms:=  kontaktInfo.AddChild('varselSmsMobilnummer');
    sms.Text:= '11223344'; 
    oppgaver:= leveranse.AddChild('oppgaver');


<?xml version="1.0" encoding="utf-8"?>
<melding xmlns="urn:ske:fastsetting:innsamling:slakt:2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="&quot;urn:ske:fastsetting:innsamling:slakt:2.0 slakt2.0.xsd&quot;">
*<leveranse xmlns="">*
    <oppgavegiver>
      <organisasjonsnummer>123456789</organisasjonsnummer>
      <organisasjonsnavn>Company</organisasjonsnavn>
      <kontaktinformasjon>
        <navn>Petter</navn>
        <telefonnummer>99887766</telefonnummer>
        <varselEpostadresse>petter@mailserver.no</varselEpostadresse>
        <varselSmsMobilnummer>11223344</varselSmsMobilnummer>
      </kontaktinformasjon>
    </oppgavegiver>
    <inntektsaar>2012</inntektsaar>
    <oppgavegiversLeveranseReferanse>1</oppgavegiversLeveranseReferanse>
    <leveransetype>Ordinær</leveransetype>
    <oppgaver/>
  </leveranse>
  </melding>
1
Petter
10/25/2012 9:15:39 AM
embarcadero.delphi.xml 291 articles. 0 followers. Follow

4 Replies
4363 Views

Similar Articles

[PageSpeed] 54

Petter wrote:

> root.Attributes['xmlns'] := 'urn:ske:fastsetting:innsamling:slakt:2.0';
> root.Attributes['xmlns:xsi'] := 'http://www.w3.org/2001/XMLSchema-instance';

Don't use the Attributes property to set namespaces maually like that.  You 
have to use the DeclareNamespace() method instead.  Namepaces have to be 
tracked internally, so it is not enough to simply create the attribute values 
by themselves.  Try this instead:

{code:delphi}
root.DeclareNamespace('', 'urn:ske:fastsetting:innsamling:slakt:2.0');
root.DeclareNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
{code}

--
Remy Lebeau (TeamB)
1
Remy
10/25/2012 5:36:58 PM
Hi Remy.

Tried your suggestion, but same result....

<leveranse xmlns=""> still get a "xmlns" attribute that's empty.

Any other idea?

Petter

Edited by: Petter Topp on Oct 25, 2012 11:32 PM
0
Petter
10/26/2012 6:34:39 AM
Petter wrote:

> Tried your suggestion, but same result....
> 
> <leveranse xmlns=""> still get a "xmlns" attribute that's empty.

When you add a child node to a parent node, it inherits the parent's namespace 
unless you specify a different namespace.  In this case, the "melding" node 
has multiple namespaces, so the "leveranse" node does not know which namespace 
to inherit, so it declares a new namespace for itself.  All you have to do 
is pass the desired namespace when calling AddChild(), then the blank namespace 
declaration on "leveranse" will disappear, eg:

{code:delphi}
leveranse := root.AddChild('leveranse', 'urn:ske:fastsetting:innsamling:slakt:2.0');
{code}

You have to specify the full namespace URI, you cannot specify a namespace 
prefix that was previously declared in a higher node.

--
Remy Lebeau (TeamB)
1
Remy
10/26/2012 5:41:15 PM
Great help Remy
0
Petter
11/7/2012 9:17:58 AM
Reply:

Similar Artilces:

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Stop xmlns="" being added as attribute to child element.
Hi, I am trying to open an XML file, clear the child elements of an element and then add a new child element. This I can do successfully, except that when I do it adds xmlns="" as an attribute of my element. Example: Why is it doing things? This is my code: string FileName = @"C:\Documents and Settings\whitfies\My Documents\test.xml"; XmlDocument Doc = new XmlDocument(); Doc.Load(FileName); Doc.DocumentElement.LastChild.RemoveAll(); XmlElement El = Doc.CreateElement("Test"); Doc.DocumentElement.LastChild.A...

superreview requested: [Bug 251274] Error: [Exception... "Node was not found" code: "8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)" location: "chrome://inspector/content/inspector.xml Line:
Boris Zbarsky <bzbarsky@mit.edu> has asked neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> for superreview: Bug 251274: Error: [Exception... "Node was not found" code: "8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)" location: "chrome://inspector/content/inspector.xml Line: 684"] https://bugzilla.mozilla.org/show_bug.cgi?id=251274 Attachment 193251: Fix https://bugzilla.mozilla.org/attachment.cgi?id=193251&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> This just makes su...

"Attribute" vs. "Property"
I just want to verify that I properly understand the use of these two terms in Perl 6. * An "attribute" is a data member of a class. * A "property" is a piece of metadata on a...uh...thing -- e.g., on an attribute, on a class, or on a method. Do I have it right? For some reason, I've always referred to class data members as "properties", and thought of metadata on such things as "attributes" -- the reverse of the above. This despite the use of "attribute" in the above usage in Damian's book. So do I just need to t...

superreview granted: [Bug 251274] [FIX]Error: [Exception... "Node was not found" code: "8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)" location: "chrome://inspector/content/inspector.xml Lin
neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> has granted Boris Zbarsky <bzbarsky@mit.edu>'s request for superreview: Bug 251274: [FIX]Error: [Exception... "Node was not found" code: "8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)" location: "chrome://inspector/content/inspector.xml Line: 684"] https://bugzilla.mozilla.org/show_bug.cgi?id=251274 Attachment 193251: Fix https://bugzilla.mozilla.org/attachment.cgi?id=193251&action=edit ------- Additional Comments from neil@parkwaycc.co.uk <neil.parkwa...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

XML "Reader" that allows me to access specific nodes and attributes efficiently?
Hi, I'm pretty much a newcomer when it comes to XML Development and I'm hoping you can help me. The application I've inherited is a bit of a mess because SQL statements are littered all over the place, making it difficult to find, tune and reuse queries as well as validating them in a semi automated way. Besides, if we wanted to support SQL Server as well as Oracle, we'd have no way of storing the different forms of the query. So I've started creating an XML file to move all the SQL into. The current draft XML looks something like:   <?xml version="1.0" ?> &nb...

howto: Copy value of attribute "comment" to attribute "mail"
Hello. At one eDir (nw6.5.6) almost all users were created using NWAdmin. As it doesn't offer access to "mail" attribute, the email address of the users was written to the attribute "comment". I'm looking for a possiblity to - search for user objects throughout the tree - check, if there already is a email address in "mail" - if not, check, if "comment" has a valid email address - if that is fact, *WRITE* this one to "mail" - next user I was wondering if I could do this through LDAP queries, but after searching...

double quote
hello there...  i tried everything of think but not working the way i wanted to be... not sure what i'm missing...i'm generating a <span> in code behind and then using in javascript.... here is what i'm doing code behind: int i=0string _keywordID = "keyword";string _name = row["visit_info_nm"].ToString().Trim(); String _getElementByID = String.Format("<span id='{0}' OnClick = \"document.getElementById('{1}').value='{2}';\">{3}</span><br>", i, _keywordID, _name, _name); here is what it generate : <span id='1' OnClick = \"document.getElementById('keyword')...

Replacing "\\" with "\"
Hi all I'm getting this value from a CheckBoxList control - a location of file, i have to remove "\\" and replace it with "\" and pass it to Query, how to do it, i tried with Replace, but coud'nt suceed. "\\\\Blaze10xp\\BLZ_SFS_07\\Sample Excel Files\\Excel Files\\report2.xls" thank's in advance - Prakash.C you tried Replace like this? string newstring = oldstring.Replace(@"\\",@"\");Plese, do not forget to click "Mark as Answer" on the post that helped you. Thanx!My blog: Scenes From A Developer Memory yes i tr...

replace the "." with a ","
Oi.... I need to build a small programm in ASP.NET and chose to use C# for it.Now i got everything working but there's one little problem.the first textbox is a double. I need to make it so that when someone enters a "." then it gets replaced by a ","any ideas?Ghan  string blah = "4.2.2.2";blah = blah.Replace(".", ",");Ryan Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

"Me" is better than "You"
Yes I know, strings are frozen. But let me talk about it, I really can't get through the idea of a PC talkin to me. I consider my PC as an extension of myself, not a dumb companion who addresses Me as You. Yes there are times when I get angry with Him while I work and get wrong calculations etc.., but it really is my fault, Me using wrong istructions and eventually wanting to find someone else to blame, but it's Me. And yes, I consider Thunderbird my mail program, reading my mail on my PC as Me. So I personally like to have Me in the header bar as a compact address ...

"Using" or "With"
Hi all Please can someone enlighten to me as regards the difference with the "Using" and "With" statement when accessing data - which is better, what are the limitations and/or any pointers. Many thanks. Regards DaveDavid WinchesterPlease mark as answer if this is the solution.  using gives you the ability to use the connection and it closes the connection directlly after you finish using it. and there is no need to try- cach - finaly. there is no limitation on using USING keywordMuhanad YOUNISMCSD.NETMy Blog || My Photos || LinkedIn I have a dataobject the re...

Web resources about - xmlns="" attribute on child node - embarcadero.delphi.xml

Resources last updated: 2/12/2016 2:43:20 PM