|
|
Rank: Newbie
Joined: 7/16/2009 Posts: 3
|
I create the code (c#) for an XSD., when exporting a sample xml from XSD it adds the correct tags to each xml node... in the SaveToFile method.. it only adds the node with a xmlns attribute for where the node is from... and example will explain it better
example., when exporting sample xml from xmlspay i get <ext:TransactionMetadata> <ext:SubmittingAgencyORIIdentification> <nc:IdentificationID>TESTVAL</nc:IdentificationID> </ext:SubmittingAgencyORIIdentification> <ext:TransactionActionCode>NEW</ext:TransactionActionCode> <ext:TransactionDateTime> <nc:DateTime>2009-03-22T07:34:56</nc:DateTime> </ext:TransactionDateTime> <ext:TransactionSequenceIdentification> <nc:IdentificationID>AEREA</nc:IdentificationID> </ext:TransactionSequenceIdentification> </ext:TransactionMetadata>
when i use savetofile i get <TransactionMetadata> <SubmittingAgencyORIIdentification> <IdentificationID xmlns="http://niem.gov/niem/niem-core/2.0">TESTVAL</IdentificationID> </SubmittingAgencyORIIdentification> <TransactionActionCode>NEW</TransactionActionCode> <TransactionDateTime> <DateTime xmlns="http://niem.gov/niem/niem-core/2.0">2009-03-22T07:34:56</DateTime> </TransactionDateTime> <TransactionSequenceIdentification> <IdentificationID xmlns="http://niem.gov/niem/niem-core/2.0">AEREA</IdentificationID> </TransactionSequenceIdentification> </TransactionMetadata>
is it possible to have the generated code export xml as the first example? where instead of schema location, it uses the name with the tag?
|
|
Rank: Advanced Member
Joined: 7/17/2008 Posts: 185 Location: Minutiae, Triviality
|
yes...
1) look at the ".Node" property, which is a reference to the node in the underlying DOM.
2) Setting the foo.Node.Prefix property to "ext" will cause the serializer to output
<ext:foo>...</ext:foo>
3) To get the namespace into the element
<ext:foo xmlns:ext="http://www.ext.foo/"> ... </ext:foo>
into the element is also possible using the .Node, but I don't have that example in front of me (it's on the work machine). I'll post it in a followup later this morning.
|
|
Rank: Advanced Member
Joined: 7/17/2008 Posts: 185 Location: Minutiae, Triviality
|
Code:protected static void Example() { // Example code to create and save a structure: sluishe.bound doc = sluishe.bound.CreateDocument(); sluishe.unameType root = doc.ums.Append(); System.Xml.XmlElement xmlElm = (System.Xml.XmlElement) root.Node;
xmlElm.Prefix = "xn";
System.Xml.XmlAttribute myAttr = xmlElm.OwnerDocument.CreateAttribute( "xmlns", "xn", "http://www.w3.org/2000/xmlns/"); myAttr.Value = "http://xmlns.sluishe.com/xn/1.0"; xmlElm.SetAttributeNode(myAttr);
myAttr = xmlElm.OwnerDocument.CreateAttribute( "xmlns", "xsi", "http://www.w3.org/2000/xmlns/"); myAttr.Value = "http://www.w3.org/2001/XMLSchema-instance"; xmlElm.SetAttributeNode(myAttr); doc.SaveToFile("C:\\Temp\\sluishe.xml", true); }
That's the idea. It would create
Code: <xn:ums xmlns:xn="http://xmlsn.sluishe.com/xn/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> ... </xn:ums>
|
|
Rank: Newbie
Joined: 7/16/2009 Posts: 3
|
Thank you for the example :)
I see no problem doing that for the root node as it would need to be done just once.. but my schema imports roughly 5 others., and every single node would need its prefix, would i have to manually create the correct prefix for every node?
from the short following sample
<ext:TransactionMetadata> <ext:SubmittingAgencyORIIdentification> <nc:IdentificationID>TESTVAL</nc:IdentificationID> </ext:SubmittingAgencyORIIdentification> <ext:TransactionActionCode>NEW</ext:TransactionActionCode> <ext:TransactionDateTime> <nc:DateTime>2009-03-22T07:34:56</nc:DateTime> </ext:TransactionDateTime> <ext:TransactionSequenceIdentification> <nc:IdentificationID>AEREA</nc:IdentificationID> </ext:TransactionSequenceIdentification> </ext:TransactionMetadata>
I would need to 1. add the prefix ext to TransactionMetadata 2. add the prefix ext to SubmittingAgencyORIIdentification 3. add the prefix nc IdentificationID 4. add the prefix ext to TransactionActionCode 5. add the prefix ext to TransactionDateTime .... this would also require me to correctly add the right prefix.. by giving me control... i could have a type and make nc into nv...
no way to have it do this all automatically? :)
thank you.
|
|
Rank: Advanced Member
Joined: 7/17/2008 Posts: 185 Location: Minutiae, Triviality
|
automatically? Not that I know of.
As you said, you only need to xmlns:foo="foo" in the outer element, inner elements simply ....Node.Prefix = "foo" when you create them.
There might be some weird DOM toggle someplace, but that's for someone else to look up.
|
|
Rank: Newbie
Joined: 7/16/2009 Posts: 3
|
thanks for your reply :) i tried out the sample code and added the outer elements... i think its partly lame that it doesn't see that the outer elements are there in the XML and only adds the node.prefix., im going to export a sample using the code i have and hope that the XML parsing webservice doesnt care about the prefix.. otherwise ill have to add 50-100 lines of Node.prefix.... and undo a lot of my
item.subitem.append.subitem1.append.subitem2.append.subitem3.append
and break them appart so that i can do a node.prefix for each parent node... :(
|
|
|
guest |