I want to create via C# code XML like this:
<Title>
<A>
<aa=aa,cc=cc,dd=dd/>
</A>
开发者_C百科 <B>
<bbbbbbbbbbbbb.udl/>
</B>
</Title>
With what code should i create tree like thist? How to put symbols like "=" and "." inside the name?
Only by using a StringBuilder, since the sample you gave is not valid XML.
Did you mean to use syntax like:
<aa foo="bb" bar="cc"/>
you can use xml serialization, and change the name of elements:
[XmlRootAttribute(ElementName="bbb.udl", IsNullable=false)]
public class BBB
{
public BBB()
{
//default constructor
}
private String someField;
}
You an use periods but the equals sign is not a valid character for an xml tag.
XmlWriter will helps writing xml. http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx
This is not XML since it cannot be parsed by a XML-parser. You can use the W3C Validator to check what is XML and what is not.
I would make my own class - HackyMLBuilder
that as a StringBuilder
inside. This class can have methods for adding nodes, etc.
The "=" inside "names" are in XML called attributes inside elements or tags and must be declared like this: <a aa="aa" bb="bb" />
精彩评论