I cannot create an XML element with a namespace

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have got to create an XML file using XMLDocument() like this:

<?xml version="1.0" encoding="UTF-8" ?>
- <xml xmlns:xi="http://www.dpr.co.uk/mplcvalidationtables/">
- <xi:table ValidationTable="3" Heading="A/C Control Status"
Description="Description">
<item Code="AA" CodeDescription="Arrears Arrangement" />
<item Code="AD" CodeDescription="Arrears Arrangement Defaulted" />
<item Code="D" CodeDescription="Deceased" />
</ xi:table>
- < xi:table ValidationTable="4" Heading="Capital Adequacy Grp"
Description="Group Description">
<item Code="0" CodeDescription="Capital Adequacy Group 0" />
<item Code="1" CodeDescription="Adequacy Group 1" />
</ xi:table>

I got mostly all this, but I cannot create an XML element with a namespace
(xi:table), the prefix property seems not to have any effect. And the element
created it’s only <table………………>


Thanks,
Filippo
 
I have got to create an XML file using XMLDocument() like this:

<?xml version="1.0" encoding="UTF-8" ?>
- <xml xmlns:xi="http://www.dpr.co.uk/mplcvalidationtables/">
- <xi:table ValidationTable="3" Heading="A/C Control Status"
Description="Description">
<item Code="AA" CodeDescription="Arrears Arrangement" />
<item Code="AD" CodeDescription="Arrears Arrangement Defaulted" />
<item Code="D" CodeDescription="Deceased" />
</ xi:table>
- < xi:table ValidationTable="4" Heading="Capital Adequacy Grp"
Description="Group Description">
<item Code="0" CodeDescription="Capital Adequacy Group 0" />
<item Code="1" CodeDescription="Adequacy Group 1" />
</ xi:table>

I got mostly all this, but I cannot create an XML element with a namespace
(xi:table), the prefix property seems not to have any effect. And the element
created it's only <table..................>

Thanks,
Filippo

try this.

XmlNode oNode = oXML.CreateElement("xi:Table","xi");

-
shashank kadge
 
doing

newnode = xDoc2.CreateElement("xi:table","xi"); as you said I got

<xi:table ValidationTable="4" Heading="Capital Adequacy Grp"
Description="Group Description" xmlns:xi="xi">

but I do not need the .....xmlns:xi="xi"... and it is also wrong,

this is declared at the top for the XML document:

<xml xmlns:xi="http://www.dpr.co.uk/mplcvalidationtables/">

Thanks,
Filippo
 
doing

newnode = xDoc2.CreateElement("xi:table","xi"); as you said I got

<xi:table ValidationTable="4" Heading="Capital Adequacy Grp"
Description="Group Description" xmlns:xi="xi">

but I do not need the .....xmlns:xi="xi"... and it is also wrong,

this is declared at the top for the XML document:

<xml xmlns:xi="http://www.dpr.co.uk/mplcvalidationtables/">

Thanks,
Filippo








- Show quoted text -

okay. try this.
*************************************************************
XmlDocument oXML = new XmlDocument();
XmlDeclaration oDec = oXML.CreateXmlDeclaration("1.0","","yes");
oXML.PrependChild(oDec);

XmlElement oRoot = oXML.CreateElement("xi","AD","http://
www.dpr.co.uk/mplcvalidationtables");
oXML.AppendChild(oRoot);

for(int iLoop=0;iLoop<3;iLoop++)
{
XmlNode oNode = oXML.CreateElement("xi","Table","http://
www.dpr.co.uk/mplcvalidationtables");
oXML.DocumentElement.AppendChild(oNode);

}

MessageBox.Show(oXML.OuterXml);
*************************************************************

let me know if u find any other way.

-
shashank kadge
 
Back
Top