Last post Jan 05, 2015 10:38 AM by supermanNUM1
Member
62 Points
311 Posts
Jan 04, 2015 08:16 AM|supermanNUM1|LINK
HI,
My XML should be below format.
<?xml version="1.0"?> <Root xmlns="VirhesXSDSchema"> <Virhe> <ErrorId>DD-123</ErrorId> <ErrorName>aaaaaaa</ErrorName> <ErrorDescription>Monitor</ErrorDescription> <CreatedDate>2001-10-26</CreatedDate> <CreatedBy>Monitor</CreatedBy> <ErrorLocation>age</ErrorLocation> </Virhe> </Root>
I generated - Root and ok for the element. But when i generate it doesnt work
XmlDocument doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); XmlNode rootNode = doc.CreateElement("Root"); XmlAttribute attrRootNote = doc.CreateAttribute("xmlns","xx"); <----- I do not need "xx" attrRootNote.Value= "DoctorXSDSchema"; rootNode.Attributes.Append(attrRootNote); doc.AppendChild(rootNode); XmlNode patientNode = doc.CreateElement("Patient"); rootNode.AppendChild(patientNode);
Please advice
Jan 04, 2015 09:45 AM|supermanNUM1|LINK
I tried below way
string myNS ="VirheXSDschemas"; XmlNode rootNode = doc.AppendChild(doc.CreateElement("Root", myNS)); XmlAttribute attr = doc.CreateAttribute("xmlns","xsi", "http://www.w3.org/2000/xmlns/"); attr.InnerText = "http://www.w3.org/2001/XMLSchema-instance"; rootNode.Attributes.Append(attr);
It comes with
<Root xmlns="VirheXSDschemas"> <Patient xmlns=""> <-- I do not want
Contributor
2290 Points
493 Posts
Jan 04, 2015 12:29 PM|santhoshje|LINK
Try following code
XmlDocument doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); XmlElement rootElement = doc.CreateElement("Root"); rootElement.SetAttribute("xmlns", "VirhesXSDSchema"); XmlElement virheElement = doc.CreateElement("Virhe"); rootElement.AppendChild(virheElement); doc.AppendChild(rootElement);
Jan 05, 2015 01:23 AM|supermanNUM1|LINK
Hi,
I got this error, when i used your code.
Jan 05, 2015 10:38 AM|supermanNUM1|LINK
This below link answered
http://forums.asp.net/t/2027752.aspx?how+to+take+out+xml+attribute+from+xml+node+by+c+
Member
62 Points
311 Posts
generating xml attribute is not working
Jan 04, 2015 08:16 AM|supermanNUM1|LINK
HI,
My XML should be below format.
<?xml version="1.0"?>
<Root xmlns="VirhesXSDSchema">
<Virhe>
<ErrorId>DD-123</ErrorId>
<ErrorName>aaaaaaa</ErrorName>
<ErrorDescription>Monitor</ErrorDescription>
<CreatedDate>2001-10-26</CreatedDate>
<CreatedBy>Monitor</CreatedBy>
<ErrorLocation>age</ErrorLocation>
</Virhe>
</Root>
I generated - Root and ok for the element. But when i generate it doesnt work
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
XmlNode rootNode = doc.CreateElement("Root");
XmlAttribute attrRootNote = doc.CreateAttribute("xmlns","xx"); <----- I do not need "xx"
attrRootNote.Value= "DoctorXSDSchema";
rootNode.Attributes.Append(attrRootNote);
doc.AppendChild(rootNode);
XmlNode patientNode = doc.CreateElement("Patient");
rootNode.AppendChild(patientNode);
Please advice
Member
62 Points
311 Posts
Re: generating xml attribute is not working
Jan 04, 2015 09:45 AM|supermanNUM1|LINK
I tried below way
string myNS ="VirheXSDschemas";
XmlNode rootNode = doc.AppendChild(doc.CreateElement("Root", myNS));
XmlAttribute attr = doc.CreateAttribute("xmlns","xsi", "http://www.w3.org/2000/xmlns/");
attr.InnerText = "http://www.w3.org/2001/XMLSchema-instance";
rootNode.Attributes.Append(attr);
It comes with
<Root xmlns="VirheXSDschemas">
<Patient xmlns=""> <-- I do not want
Please advice
Contributor
2290 Points
493 Posts
Re: generating xml attribute is not working
Jan 04, 2015 12:29 PM|santhoshje|LINK
Try following code
Member
62 Points
311 Posts
Re: generating xml attribute is not working
Jan 05, 2015 01:23 AM|supermanNUM1|LINK
Hi,
I got this error, when i used your code.
The prefix '' cannot be redefined from '' to 'VirhesXSDSchema' within the same start element tag.
Member
62 Points
311 Posts
Re: generating xml attribute is not working
Jan 05, 2015 10:38 AM|supermanNUM1|LINK
This below link answered
http://forums.asp.net/t/2027752.aspx?how+to+take+out+xml+attribute+from+xml+node+by+c+