XML Help

  • Thread starter Thread starter Mike Fellows
  • Start date Start date
M

Mike Fellows

Im using a XmlTextWriter to create an xml document however the
doucmentation for the XML document that I have been given wants me to
create a xml document with the following:

<OrderType Code='STC'>Stock Check</OrderType>

how do I add the code='STC' to the Start Element?

Thanks

Mike Fellows
 
Mike said:
Im using a XmlTextWriter to create an xml document however the
doucmentation for the XML document that I have been given wants me to
create a xml document with the following:

<OrderType Code='STC'>Stock Check</OrderType>

how do I add the code='STC' to the Start Element?

It is an attribute with name "Code" and value "STC":

writer.WriteStartElement("OrderType")
writer.WriteAttributeString("Code", "STC")
writer.WriteString("Stock Check")
writer.WriteEndElement()
 
It is an attribute with name "Code" and value "STC":

writer.WriteStartElement("OrderType")
writer.WriteAttributeString("Code", "STC")
writer.WriteString("Stock Check")
writer.WriteEndElement()

Thanks for that I was just playing with that same code however i always end
up with double quoation marks " when the document spec lists '

It might work

Thanks again
 
Mike said:
Thanks for that I was just playing with that same code however i always end
up with double quoation marks " when the document spec lists '

XML allows single or double quotes to be used to delimit attribute
values, it does not make any difference in terms of the semantics of the
XML whether single or double quotes are used.

XmlTextWriter has a property named QuoteChar that you can set as needed,
if you really think you need single quote delimiters.
 
@TK2MSFTNGP03.phx.gbl:








Thanks for that I was just playing with that same code however i always end  
up with double quoation marks " when the document spec lists '

It might work

Double quotes are the standard delimiters for attribute values in XML.
 
XML allows single or double quotes to be used to delimit attribute
values, it does not make any difference in terms of the semantics of the
XML whether single or double quotes are used.

XmlTextWriter has a property named QuoteChar that you can set as needed,
if you really think you need single quote delimiters.

I found it interesting that if you force single quotes with, say, a
text editor, then open the xml in IE, IE translates the single qotes
to double quotes.
 
Joe said:
I found it interesting that if you force single quotes with, say, a
text editor, then open the xml in IE, IE translates the single qotes
to double quotes.

Well IE uses an XSL stylesheet to transform the XML into a HTML document
rendering a tree of the XML document with some script to allow
collapsing and expanding nodes. As the data model the XSL stylesheet
works on does only store nodes of a certain type like element nodes and
attribute nodes but certainly not any delimiters used in the markup
source it is not surprising that the view IE presents does not preserve
any such source details.
 
Well IE uses an XSL stylesheet to transform the XML into a HTML document
rendering a tree of the XML document with some script to allow
collapsing and expanding nodes. As the data model the XSL stylesheet
works on does only store nodes of a certain type like element nodes and
attribute nodes but certainly not any delimiters used in the markup
source it is not surprising that the view IE presents does not preserve
any such source details.


Thanks for all the replies, I have it working perfectly now

Thanks again
 
Back
Top