HighTechTalks DotNet Forums  

single quote xml value

Dotnet XML microsoft.public.dotnet.xml


Discuss single quote xml value in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
dotnetnoob
 
Posts: n/a

Default single quote xml value - 06-26-2006 , 03:51 PM






EvtEnrollAttr.Value = "3748"
EvtEnrollElem.Attributes.Append(EvtEnrollAttr)

i need the attr value to be <stuff ID = '3748'> in single quote

how can i do that with visual basic.net?

thanks


Reply With Quote
  #2  
Old   
Sanjib Biswas
 
Posts: n/a

Default Re: single quote xml value - 06-26-2006 , 09:46 PM






Use EvtEnrollAttr.Value = "'3748'" (single quote's inside double quote)

"dotnetnoob" <dotnetnoob (AT) discussions (DOT) microsoft.com> wrote

Quote:
EvtEnrollAttr.Value = "3748"
EvtEnrollElem.Attributes.Append(EvtEnrollAttr)

i need the attr value to be <stuff ID = '3748'> in single quote

how can i do that with visual basic.net?

thanks




Reply With Quote
  #3  
Old   
Oleg Tkachenko [MVP]
 
Posts: n/a

Default Re: single quote xml value - 06-27-2006 , 03:51 AM



dotnetnoob wrote:
Quote:
EvtEnrollAttr.Value = "3748"
EvtEnrollElem.Attributes.Append(EvtEnrollAttr)

i need the attr value to be <stuff ID = '3748'> in single quote

how can i do that with visual basic.net?
Use QuoteChar property of the XmlTextWriter class:
http://msdn2.microsoft.com/en-us/library/system.xml.xmltextwriter.quotechar.aspx


--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net


Reply With Quote
  #4  
Old   
dotnetnoob
 
Posts: n/a

Default Re: single quote xml value - 06-27-2006 , 08:04 AM



i got error Cannot set a value on node type 'Element'. when i try single
quote inside double quote.

is there an example of how to use textwriter quotechar?

thank

"Sanjib Biswas" wrote:

Quote:
Use EvtEnrollAttr.Value = "'3748'" (single quote's inside double quote)

"dotnetnoob" <dotnetnoob (AT) discussions (DOT) microsoft.com> wrote in message
news:7B2A0B48-6CFD-4868-8D15-4BF9E5C24CA5 (AT) microsoft (DOT) com...
EvtEnrollAttr.Value = "3748"
EvtEnrollElem.Attributes.Append(EvtEnrollAttr)

i need the attr value to be <stuff ID = '3748'> in single quote

how can i do that with visual basic.net?

thanks





Reply With Quote
  #5  
Old   
dotnetnoob
 
Posts: n/a

Default Re: single quote xml value - 06-27-2006 , 08:21 AM



ok, i figure out the error and by using single quote inside double quote i
got this value

<EventEnrollment InstanceNumber="'3748'">

it is still not the result that i want i need it to be '3748'

thanks

"Sanjib Biswas" wrote:

Quote:
Use EvtEnrollAttr.Value = "'3748'" (single quote's inside double quote)

"dotnetnoob" <dotnetnoob (AT) discussions (DOT) microsoft.com> wrote in message
news:7B2A0B48-6CFD-4868-8D15-4BF9E5C24CA5 (AT) microsoft (DOT) com...
EvtEnrollAttr.Value = "3748"
EvtEnrollElem.Attributes.Append(EvtEnrollAttr)

i need the attr value to be <stuff ID = '3748'> in single quote

how can i do that with visual basic.net?

thanks





Reply With Quote
  #6  
Old   
Martin Honnen
 
Posts: n/a

Default Re: single quote xml value - 06-27-2006 , 08:47 AM





dotnetnoob wrote:


Quote:
is there an example of how to use textwriter quotechar?

Here is a simple example with C#:

XmlTextWriter xmlWriter = new XmlTextWriter(@"file.xml",
System.Text.Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.QuoteChar = '\'';
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("EventEnrollment");
xmlWriter.WriteAttributeString("InstanceNumber", "3748");
xmlWriter.WriteEndDocument();
xmlWriter.Close();

file.xml then has the contents

<?xml version='1.0' encoding='utf-8'?>
<EventEnrollment InstanceNumber='3748' />

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #7  
Old   
dotnetnoob
 
Posts: n/a

Default Re: single quote xml value - 06-27-2006 , 09:36 AM



how do you insert it into the specific area of the xml file. i have done it
with DOM, but i just can't get the attribute value to go from double quote to
single quote. here is my code

Dim newEvtEnrollElem As XmlElement = Nothing
Dim str1, str2 As String

str1 = strPath.Substring(0, strPath.LastIndexOf("."))
str2 = str1.ToString.Remove(0, 42)

Dim wrtr As XmlTextWriter = New XmlTextWriter("C:\" + str2 + ".xml",
Encoding.Unicode)

newEvtEnrollElem =
CType(xDoc.SelectSingleNode("AutomationControl/EventEnrollments"), XmlElement)

str1 = strPath.Substring(0, strPath.LastIndexOf("."))
str2 = str1.ToString.Remove(0, 42)

If newEvtEnrollElem IsNot Nothing Then
Dim EvtEnrollElem As XmlElement =
xDoc.CreateElement("EventEnrollment")
Dim EvtEnrollAttr As XmlAttribute =
xDoc.CreateAttribute("InstanceNumber")

EvtEnrollAttr.Value = "'\'" + "3748" + "'\'"
EvtEnrollElem.Attributes.Append(EvtEnrollAttr)

EvtEnrollElem.InnerXml =
"<BackwardReferences/><EventEnrollmentProperties><EnabledReference/><EventParameters><SetpointReference/></EventParameters><EventSources/></EventEnrollmentProperties><GeneralProperties><Desc ription/></GeneralProperties>"

Dim EvtEnrollProp_AckRequiredAttrNode As XmlAttribute =
xDoc.CreateAttribute("AckRequired")
EvtEnrollProp_AckRequiredAttrNode.Value = "0"
Dim EvtEnrollProp_EvtEnabledAttrNode As XmlAttribute =
xDoc.CreateAttribute("EventEnable")
EvtEnrollProp_EvtEnabledAttrNode.Value = "0"
Dim EvtEnrollProp_EvtTypeAttrNode As XmlAttribute =
xDoc.CreateAttribute("EventType")
EvtEnrollProp_EvtTypeAttrNode.Value = "0"
Dim EvtEnrollProp_NotifyClassAttrNode As XmlAttribute =
xDoc.CreateAttribute("NotifyClass")
EvtEnrollProp_NotifyClassAttrNode.Value = "0"
Dim EvtEnrollProp_NotifyTypeAttrNode As XmlAttribute =
xDoc.CreateAttribute("NotifyType")
EvtEnrollProp_NotifyTypeAttrNode.Value = "0"
Dim EvtEnrollProp_PresentValueAttrNode As XmlAttribute =
xDoc.CreateAttribute("PresentValue")
EvtEnrollProp_PresentValueAttrNode.Value = "0"
Dim EvtEnrollProp_ToFaultTextAttrNode As XmlAttribute =
xDoc.CreateAttribute("ToFaultText")
EvtEnrollProp_ToFaultTextAttrNode.Value = ""
Dim EvtEnrollProp_ToNormalTextAttrNode As XmlAttribute =
xDoc.CreateAttribute("ToNormalText")
EvtEnrollProp_ToNormalTextAttrNode.Value = ""
Dim EvtEnrollProp_ToOffNormalTextAttrNode As XmlAttribute =
xDoc.CreateAttribute("ToOffNormalText")
EvtEnrollProp_ToOffNormalTextAttrNode.Value = ""


EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_AckRequiredAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_EvtEnabledAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_EvtTypeAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_NotifyClassAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_NotifyTypeAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_PresentValueAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_ToFaultTextAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_ToNormalTextAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_ToOffNormalTextAttrNo de)

Dim EnRef_ObjKeyAttrNode As XmlAttribute =
xDoc.CreateAttribute("ObjectKey")
EnRef_ObjKeyAttrNode.Value = ""
Dim EnRef_PropName As XmlAttribute =
xDoc.CreateAttribute("PropertyName")
EnRef_PropName.Value = ""


EvtEnrollElem.Item("EventEnrollmentProperties").It em("EnabledReference").SetAttributeNode(EnRef_ObjK eyAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EnabledReference").SetAttributeNode(EnRef_Prop Name)

Dim EvtPara_BitMaskAttrNode As XmlAttribute =
xDoc.CreateAttribute("BitMask")
EvtPara_BitMaskAttrNode.Value = "0"
Dim EvtPara_DeadbandAttrNode As XmlAttribute =
xDoc.CreateAttribute("Deadband")
EvtPara_DeadbandAttrNode.Value = ""
Dim EvtPara_HighDiffLimitAttrNode As XmlAttribute =
xDoc.CreateAttribute("HighDiffLimit")
EvtPara_HighDiffLimitAttrNode.Value = ""
Dim EvtPara_HighLimitAttrNode As XmlAttribute =
xDoc.CreateAttribute("HighLimit")
EvtPara_HighLimitAttrNode.Value = ""
Dim EvtPara_ListOfBitStringValuesAttrNode As XmlAttribute =
xDoc.CreateAttribute("ListOfBitStringValues")
EvtPara_ListOfBitStringValuesAttrNode.Value = ""
Dim EvtPara_ListOfValuesAttrNode As XmlAttribute =
xDoc.CreateAttribute("ListOfValues")
EvtPara_ListOfValuesAttrNode.Value = ""
Dim EvtPara_LowDiffLimitAttrNode As XmlAttribute =
xDoc.CreateAttribute("LowDiffLimit")
EvtPara_LowDiffLimitAttrNode.Value = ""
Dim EvtPara_LowLimitAttrNode As XmlAttribute =
xDoc.CreateAttribute("LowLimit")
EvtPara_LowLimitAttrNode.Value = ""
Dim EvtPara_RefPropIncrAttrNode As XmlAttribute =
xDoc.CreateAttribute("ReferencedPropertyIncrement" )
EvtPara_RefPropIncrAttrNode.Value = "1"
Dim EvtPara_TimeDelayAttrNode As XmlAttribute =
xDoc.CreateAttribute("TimeDelay")
EvtPara_TimeDelayAttrNode.Value = "60"
Dim EvtPara_TimeIntervalAttrNode As XmlAttribute =
xDoc.CreateAttribute("TimeInterval")
EvtPara_TimeIntervalAttrNode.Value = "1"


EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Bit MaskAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Dea dbandAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Hig hDiffLimitAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Hig hLimitAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Lis tOfBitStringValuesAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Lis tOfValuesAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Low DiffLimitAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Low LimitAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Ref PropIncrAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Tim eDelayAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Tim eIntervalAttrNode)

Dim SetPointRef_ObjKeyAttrNode As XmlAttribute =
xDoc.CreateAttribute("ObjectKey")
SetPointRef_ObjKeyAttrNode.Value = ""
Dim SetPointRef_PropNameAttrNode As XmlAttribute =
xDoc.CreateAttribute("PropertyName")
SetPointRef_PropNameAttrNode.Value = ""


EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").Item("SetpointReference").Se tAttributeNode(SetPointRef_ObjKeyAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").Item("SetpointReference").Se tAttributeNode(SetPointRef_PropNameAttrNode)

Dim GP_AttrNode As XmlAttribute = xDoc.CreateAttribute("Attr")
GP_AttrNode.Value = "0"
Dim GP_InstNumAttrNode As XmlAttribute =
xDoc.CreateAttribute("InstanceNumber")
GP_InstNumAttrNode.Value = "3748"
Dim GP_IsConfigAttrNode As XmlAttribute =
xDoc.CreateAttribute("IsConfigured")
GP_IsConfigAttrNode.Value = "0"
Dim GP_ObjNameAttrNode As XmlAttribute =
xDoc.CreateAttribute("ObjectName")
GP_ObjNameAttrNode.Value = "test1"
Dim GP_ObjTypeAttrNode As XmlAttribute =
xDoc.CreateAttribute("ObjectType")
GP_ObjTypeAttrNode.Value = "9"
Dim GP_SchemaVerAttrNode As XmlAttribute =
xDoc.CreateAttribute("SchemaVer")
GP_SchemaVerAttrNode.Value = "1.4"
Dim GP_TraceOptionsAttrNode As XmlAttribute =
xDoc.CreateAttribute("TraceOptions")
GP_TraceOptionsAttrNode.Value = "0"


EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_AttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_InstNumAttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_IsConfigAttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_ObjNameAttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_ObjTypeAttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_SchemaVerAttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_TraceOptionsAttrNode)

newEvtEnrollElem.AppendChild(EvtEnrollElem)

End If

xDoc.WriteTo(wrtr)
wrtr.Close()
MessageBox.Show("Added new eventenrollment element")


"Martin Honnen" wrote:

Quote:

dotnetnoob wrote:


is there an example of how to use textwriter quotechar?


Here is a simple example with C#:

XmlTextWriter xmlWriter = new XmlTextWriter(@"file.xml",
System.Text.Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.QuoteChar = '\'';
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("EventEnrollment");
xmlWriter.WriteAttributeString("InstanceNumber", "3748");
xmlWriter.WriteEndDocument();
xmlWriter.Close();

file.xml then has the contents

?xml version='1.0' encoding='utf-8'?
EventEnrollment InstanceNumber='3748' /

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #8  
Old   
dotnetnoob
 
Posts: n/a

Default RE: single quote xml value - 06-27-2006 , 10:23 AM



Can someone help? is it possible to switch the value from double quote to
single quote without using the xmltextwriter quotechar

"dotnetnoob" wrote:

Quote:
EvtEnrollAttr.Value = "3748"
EvtEnrollElem.Attributes.Append(EvtEnrollAttr)

i need the attr value to be <stuff ID = '3748'> in single quote

how can i do that with visual basic.net?

thanks


Reply With Quote
  #9  
Old   
Martin Honnen
 
Posts: n/a

Default Re: single quote xml value - 06-27-2006 , 11:11 AM





dotnetnoob wrote:

Quote:
how do you insert it into the specific area of the xml file. i have done it
with DOM, but i just can't get the attribute value to go from double quote to
single quote. here is my code

Dim wrtr As XmlTextWriter = New XmlTextWriter("C:\" + str2 + ".xml",
Encoding.Unicode)
If you save with that XmlTextWriter then doing e.g.
wrtr.QuoteChar = "'"C
should suffice. Obviously that will use the single quote on any
attribute, I don't think there is a way to have just one attribute value
quoted with ' and others with ".

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.