468,268 Members | 1,984 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

How to insert a CDATA section using XPathNavigator ?

Can anybody show me how to insert a CDATA section using XPathNavigator ? I
have tried the follwing with no luck:

XmlDocument docNav = new XmlDocument();
docNav.LoadXml(xmlString);
XPathNavigator nav = docNav.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement(currentNodeName);
elem.AppendChild(doc.CreateCDataSection(dataString ));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.CreateNavigator();

nav.InsertAfter(newNav);
Regards,
Eric.-

Jun 1 '06 #1
11 6055
Hi Eric,

When you modify a XmlDocument via the XPathNavigator interface you sign up
for working with the XPath data model which is slightly different than the
XmlDocument. One such difference is the lack of CDATA sections which are
treated like any other plain text. Notice that the XPathNodeType enum
doesn't have a corresponding field for CDATA sections vs. XmlNodeType enum
which does.

In order for the nav.InsertAfter(newNav) operation to be successful, both
navigators should be positioned on meaningful items of the document. In the
sample code the navigators are positioned on the respective documents. Just
like in XmlDocument, you can't insert a document after a document. Most
likely you want the navigators positioned inside the respective documents:
static void Main()
{
XmlDocument docNav = new XmlDocument();
docNav.LoadXml("<root/>");
XPathNavigator nav = docNav.DocumentElement.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement("element");
elem.AppendChild(doc.CreateCDataSection("cdata"));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.DocumentElement.CreateNavigator();

nav.AppendChild(newNav);
}

Once you get this far, you'll notice that the lack of CDATA sections in the
XPath data model prevents you from creating the CDATA sections through the
traversal of the navigator 'newNav'. You can get around this shortcoming if
you use a XmlWriter as input for the AppendChild():
using (XmlWriter writer = nav.AppendChild()) {
writer.WriterCData("...");
}
The CDATA sections are persisted in the XmlDocument and are observable
through the DOM API. However, through the XPathNavigator interface the CDATA
sections will be exposed as Text.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
Can anybody show me how to insert a CDATA section using XPathNavigator ? I
have tried the follwing with no luck:

XmlDocument docNav = new XmlDocument();
docNav.LoadXml(xmlString);
XPathNavigator nav = docNav.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement(currentNodeName);
elem.AppendChild(doc.CreateCDataSection(dataString ));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.CreateNavigator();

nav.InsertAfter(newNav);
Regards,
Eric.-

Jun 1 '06 #2
Here is what I tried:

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

and here is what I got:

<DocumentData><![CDATA[Mzc4MDY4NzA....]]></DocumentData>

I thought that WriteCData should have kept the string as is.

Thanks for any comments.
Eric.-
"Ion Vasilian" wrote:
Hi Eric,

When you modify a XmlDocument via the XPathNavigator interface you sign up
for working with the XPath data model which is slightly different than the
XmlDocument. One such difference is the lack of CDATA sections which are
treated like any other plain text. Notice that the XPathNodeType enum
doesn't have a corresponding field for CDATA sections vs. XmlNodeType enum
which does.

In order for the nav.InsertAfter(newNav) operation to be successful, both
navigators should be positioned on meaningful items of the document. In the
sample code the navigators are positioned on the respective documents. Just
like in XmlDocument, you can't insert a document after a document. Most
likely you want the navigators positioned inside the respective documents:
static void Main()
{
XmlDocument docNav = new XmlDocument();
docNav.LoadXml("<root/>");
XPathNavigator nav = docNav.DocumentElement.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement("element");
elem.AppendChild(doc.CreateCDataSection("cdata"));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.DocumentElement.CreateNavigator();

nav.AppendChild(newNav);
}

Once you get this far, you'll notice that the lack of CDATA sections in the
XPath data model prevents you from creating the CDATA sections through the
traversal of the navigator 'newNav'. You can get around this shortcoming if
you use a XmlWriter as input for the AppendChild():
using (XmlWriter writer = nav.AppendChild()) {
writer.WriterCData("...");
}
The CDATA sections are persisted in the XmlDocument and are observable
through the DOM API. However, through the XPathNavigator interface the CDATA
sections will be exposed as Text.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
Can anybody show me how to insert a CDATA section using XPathNavigator ? I
have tried the follwing with no luck:

XmlDocument docNav = new XmlDocument();
docNav.LoadXml(xmlString);
XPathNavigator nav = docNav.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement(currentNodeName);
elem.AppendChild(doc.CreateCDataSection(dataString ));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.CreateNavigator();

nav.InsertAfter(newNav);
Regards,
Eric.-


Jun 1 '06 #3
Somehow, when I paste it here, it looks ok, but actually it looks like the
following in Notepad:

<DocumentData><![CDATA[Mzc4MDY4Nz....]]></DocumentData>


"ericms" wrote:
Here is what I tried:

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

and here is what I got:

<DocumentData><![CDATA[Mzc4MDY4NzA....]]></DocumentData>

I thought that WriteCData should have kept the string as is.

Thanks for any comments.
Eric.-
"Ion Vasilian" wrote:
Hi Eric,

When you modify a XmlDocument via the XPathNavigator interface you sign up
for working with the XPath data model which is slightly different than the
XmlDocument. One such difference is the lack of CDATA sections which are
treated like any other plain text. Notice that the XPathNodeType enum
doesn't have a corresponding field for CDATA sections vs. XmlNodeType enum
which does.

In order for the nav.InsertAfter(newNav) operation to be successful, both
navigators should be positioned on meaningful items of the document. In the
sample code the navigators are positioned on the respective documents. Just
like in XmlDocument, you can't insert a document after a document. Most
likely you want the navigators positioned inside the respective documents:
static void Main()
{
XmlDocument docNav = new XmlDocument();
docNav.LoadXml("<root/>");
XPathNavigator nav = docNav.DocumentElement.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement("element");
elem.AppendChild(doc.CreateCDataSection("cdata"));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.DocumentElement.CreateNavigator();

nav.AppendChild(newNav);
}

Once you get this far, you'll notice that the lack of CDATA sections in the
XPath data model prevents you from creating the CDATA sections through the
traversal of the navigator 'newNav'. You can get around this shortcoming if
you use a XmlWriter as input for the AppendChild():
using (XmlWriter writer = nav.AppendChild()) {
writer.WriterCData("...");
}
The CDATA sections are persisted in the XmlDocument and are observable
through the DOM API. However, through the XPathNavigator interface the CDATA
sections will be exposed as Text.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
Can anybody show me how to insert a CDATA section using XPathNavigator ? I
have tried the follwing with no luck:

XmlDocument docNav = new XmlDocument();
docNav.LoadXml(xmlString);
XPathNavigator nav = docNav.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement(currentNodeName);
elem.AppendChild(doc.CreateCDataSection(dataString ));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.CreateNavigator();

nav.InsertAfter(newNav);
Regards,
Eric.-


Jun 1 '06 #4
Here we go again, in notepad, I see the "<" and ">" that replace the "<" and
">" signs.
"ericms" wrote:
Somehow, when I paste it here, it looks ok, but actually it looks like the
following in Notepad:

<DocumentData><![CDATA[Mzc4MDY4Nz....]]></DocumentData>


"ericms" wrote:
Here is what I tried:

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

and here is what I got:

<DocumentData><![CDATA[Mzc4MDY4NzA....]]></DocumentData>

I thought that WriteCData should have kept the string as is.

Thanks for any comments.
Eric.-
"Ion Vasilian" wrote:
Hi Eric,

When you modify a XmlDocument via the XPathNavigator interface you sign up
for working with the XPath data model which is slightly different than the
XmlDocument. One such difference is the lack of CDATA sections which are
treated like any other plain text. Notice that the XPathNodeType enum
doesn't have a corresponding field for CDATA sections vs. XmlNodeType enum
which does.

In order for the nav.InsertAfter(newNav) operation to be successful, both
navigators should be positioned on meaningful items of the document. In the
sample code the navigators are positioned on the respective documents. Just
like in XmlDocument, you can't insert a document after a document. Most
likely you want the navigators positioned inside the respective documents:
static void Main()
{
XmlDocument docNav = new XmlDocument();
docNav.LoadXml("<root/>");
XPathNavigator nav = docNav.DocumentElement.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement("element");
elem.AppendChild(doc.CreateCDataSection("cdata"));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.DocumentElement.CreateNavigator();

nav.AppendChild(newNav);
}

Once you get this far, you'll notice that the lack of CDATA sections in the
XPath data model prevents you from creating the CDATA sections through the
traversal of the navigator 'newNav'. You can get around this shortcoming if
you use a XmlWriter as input for the AppendChild():
using (XmlWriter writer = nav.AppendChild()) {
writer.WriterCData("...");
}
The CDATA sections are persisted in the XmlDocument and are observable
through the DOM API. However, through the XPathNavigator interface the CDATA
sections will be exposed as Text.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
> Can anybody show me how to insert a CDATA section using XPathNavigator ? I
> have tried the follwing with no luck:
>
> XmlDocument docNav = new XmlDocument();
> docNav.LoadXml(xmlString);
> XPathNavigator nav = docNav.CreateNavigator();
>
> XmlDocument doc = new XmlDocument();
> doc.LoadXml("<DocumentData></DocumentData>");
> XmlElement elem = doc.CreateElement(currentNodeName);
> elem.AppendChild(doc.CreateCDataSection(dataString ));
> doc.DocumentElement.AppendChild(elem);
> XPathNavigator newNav = doc.CreateNavigator();
>
> nav.InsertAfter(newNav);
>
>
> Regards,
> Eric.-
>

Jun 1 '06 #5
Hi Eric,

XmlWriter.WriteCData() will preserve the input data as expected. You
shouldn't see any escaping for '<' or '>'. In your sample code what is
'dataString'? The way you've presented the code, an exception will be thrown
at runtime since the writer created by XPathNavigator.AppendChild() will
perform wellformedness checking on the provided input. The character
sequence ']]>' is disallowed inside a CDATA section according to the XML 1.0
spec.

Just to be clear,
static void Main() {
XmlDocument document = new XmlDocument();
document.LoadXml("<root/>");
XPathNavigator navigator =
document.DocumentElement.CreateNavigator();
using (XmlWriter writer = navigator.AppendChild()) {
writer.WriteCData("some < > data");
}
document.Save(Console.Out);
}
should output:
<?xml version="1.0" encoding="IBM437"?>
<root><![CDATA[some < > data]]></root>

If you still can't get the code running, feel free to upload your project
and we'll get to the bottom of this problem.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:63**********************************@microsof t.com...
Here we go again, in notepad, I see the "<" and ">" that replace the "<"
and
">" signs.
"ericms" wrote:
Somehow, when I paste it here, it looks ok, but actually it looks like
the
following in Notepad:

<DocumentData><![CDATA[Mzc4MDY4Nz....]]></DocumentData>


"ericms" wrote:
> Here is what I tried:
>
> using (XmlWriter writer = nav.AppendChild())
> {
> writer.WriteCData("<![CDATA[" + dataString + "]]>");
> }
>
> and here is what I got:
>
> <DocumentData><![CDATA[Mzc4MDY4NzA....]]></DocumentData>
>
> I thought that WriteCData should have kept the string as is.
>
> Thanks for any comments.
> Eric.-
>
>
> "Ion Vasilian" wrote:
>
> > Hi Eric,
> >
> > When you modify a XmlDocument via the XPathNavigator interface you
> > sign up
> > for working with the XPath data model which is slightly different
> > than the
> > XmlDocument. One such difference is the lack of CDATA sections which
> > are
> > treated like any other plain text. Notice that the XPathNodeType enum
> > doesn't have a corresponding field for CDATA sections vs. XmlNodeType
> > enum
> > which does.
> >
> > In order for the nav.InsertAfter(newNav) operation to be successful,
> > both
> > navigators should be positioned on meaningful items of the document.
> > In the
> > sample code the navigators are positioned on the respective
> > documents. Just
> > like in XmlDocument, you can't insert a document after a document.
> > Most
> > likely you want the navigators positioned inside the respective
> > documents:
> > static void Main()
> > {
> > XmlDocument docNav = new XmlDocument();
> > docNav.LoadXml("<root/>");
> > XPathNavigator nav =
> > docNav.DocumentElement.CreateNavigator();
> >
> > XmlDocument doc = new XmlDocument();
> > doc.LoadXml("<DocumentData></DocumentData>");
> > XmlElement elem = doc.CreateElement("element");
> > elem.AppendChild(doc.CreateCDataSection("cdata"));
> > doc.DocumentElement.AppendChild(elem);
> > XPathNavigator newNav =
> > doc.DocumentElement.CreateNavigator();
> >
> > nav.AppendChild(newNav);
> > }
> >
> > Once you get this far, you'll notice that the lack of CDATA sections
> > in the
> > XPath data model prevents you from creating the CDATA sections
> > through the
> > traversal of the navigator 'newNav'. You can get around this
> > shortcoming if
> > you use a XmlWriter as input for the AppendChild():
> > using (XmlWriter writer = nav.AppendChild()) {
> > writer.WriterCData("...");
> > }
> > The CDATA sections are persisted in the XmlDocument and are
> > observable
> > through the DOM API. However, through the XPathNavigator interface
> > the CDATA
> > sections will be exposed as Text.
> >
> > Ion
> >
> > "ericms" <er****@discussions.microsoft.com> wrote in message
> > news:A5**********************************@microsof t.com...
> > > Can anybody show me how to insert a CDATA section using
> > > XPathNavigator ? I
> > > have tried the follwing with no luck:
> > >
> > > XmlDocument docNav = new XmlDocument();
> > > docNav.LoadXml(xmlString);
> > > XPathNavigator nav = docNav.CreateNavigator();
> > >
> > > XmlDocument doc = new XmlDocument();
> > > doc.LoadXml("<DocumentData></DocumentData>");
> > > XmlElement elem = doc.CreateElement(currentNodeName);
> > > elem.AppendChild(doc.CreateCDataSection(dataString ));
> > > doc.DocumentElement.AppendChild(elem);
> > > XPathNavigator newNav = doc.CreateNavigator();
> > >
> > > nav.InsertAfter(newNav);
> > >
> > >
> > > Regards,
> > > Eric.-
> > >
> >
> >
> >

Jun 2 '06 #6
In my sample code, 'dataString' is an encoded string. As requested by our
verndor that we send a copy of PDF file encoded, in short should look similar
like:
<DocumentData><![CDATA[Mzc4MDY4Nz........]]></DocumentData>
With the following sample code:

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData(dataString);
}

The ouput is fine except that it is missing the <![CDATA[.

And when I did the following :

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

Everything is fine except that the "less than" sign is replaced with
ampersand, lt, semicolon and the greater sign is replaced with ampersand, gt,
semicolon.

I am home now, I don't have a copy of the project with me now.

"Ion Vasilian" wrote:
Hi Eric,

XmlWriter.WriteCData() will preserve the input data as expected. You
shouldn't see any escaping for '<' or '>'. In your sample code what is
'dataString'? The way you've presented the code, an exception will be thrown
at runtime since the writer created by XPathNavigator.AppendChild() will
perform wellformedness checking on the provided input. The character
sequence ']]>' is disallowed inside a CDATA section according to the XML 1.0
spec.

Just to be clear,
static void Main() {
XmlDocument document = new XmlDocument();
document.LoadXml("<root/>");
XPathNavigator navigator =
document.DocumentElement.CreateNavigator();
using (XmlWriter writer = navigator.AppendChild()) {
writer.WriteCData("some < > data");
}
document.Save(Console.Out);
}
should output:
<?xml version="1.0" encoding="IBM437"?>
<root><![CDATA[some < > data]]></root>

If you still can't get the code running, feel free to upload your project
and we'll get to the bottom of this problem.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:63**********************************@microsof t.com...
Here we go again, in notepad, I see the "<" and ">" that replace the "<"
and
">" signs.
"ericms" wrote:
Somehow, when I paste it here, it looks ok, but actually it looks like
the
following in Notepad:

<DocumentData><![CDATA[Mzc4MDY4Nz....]]></DocumentData>


"ericms" wrote:

> Here is what I tried:
>
> using (XmlWriter writer = nav.AppendChild())
> {
> writer.WriteCData("<![CDATA[" + dataString + "]]>");
> }
>
> and here is what I got:
>
> <DocumentData><![CDATA[Mzc4MDY4NzA....]]></DocumentData>
>
> I thought that WriteCData should have kept the string as is.
>
> Thanks for any comments.
> Eric.-
>
>
> "Ion Vasilian" wrote:
>
> > Hi Eric,
> >
> > When you modify a XmlDocument via the XPathNavigator interface you
> > sign up
> > for working with the XPath data model which is slightly different
> > than the
> > XmlDocument. One such difference is the lack of CDATA sections which
> > are
> > treated like any other plain text. Notice that the XPathNodeType enum
> > doesn't have a corresponding field for CDATA sections vs. XmlNodeType
> > enum
> > which does.
> >
> > In order for the nav.InsertAfter(newNav) operation to be successful,
> > both
> > navigators should be positioned on meaningful items of the document.
> > In the
> > sample code the navigators are positioned on the respective
> > documents. Just
> > like in XmlDocument, you can't insert a document after a document.
> > Most
> > likely you want the navigators positioned inside the respective
> > documents:
> > static void Main()
> > {
> > XmlDocument docNav = new XmlDocument();
> > docNav.LoadXml("<root/>");
> > XPathNavigator nav =
> > docNav.DocumentElement.CreateNavigator();
> >
> > XmlDocument doc = new XmlDocument();
> > doc.LoadXml("<DocumentData></DocumentData>");
> > XmlElement elem = doc.CreateElement("element");
> > elem.AppendChild(doc.CreateCDataSection("cdata"));
> > doc.DocumentElement.AppendChild(elem);
> > XPathNavigator newNav =
> > doc.DocumentElement.CreateNavigator();
> >
> > nav.AppendChild(newNav);
> > }
> >
> > Once you get this far, you'll notice that the lack of CDATA sections
> > in the
> > XPath data model prevents you from creating the CDATA sections
> > through the
> > traversal of the navigator 'newNav'. You can get around this
> > shortcoming if
> > you use a XmlWriter as input for the AppendChild():
> > using (XmlWriter writer = nav.AppendChild()) {
> > writer.WriterCData("...");
> > }
> > The CDATA sections are persisted in the XmlDocument and are
> > observable
> > through the DOM API. However, through the XPathNavigator interface
> > the CDATA
> > sections will be exposed as Text.
> >
> > Ion
> >
> > "ericms" <er****@discussions.microsoft.com> wrote in message
> > news:A5**********************************@microsof t.com...
> > > Can anybody show me how to insert a CDATA section using
> > > XPathNavigator ? I
> > > have tried the follwing with no luck:
> > >
> > > XmlDocument docNav = new XmlDocument();
> > > docNav.LoadXml(xmlString);
> > > XPathNavigator nav = docNav.CreateNavigator();
> > >
> > > XmlDocument doc = new XmlDocument();
> > > doc.LoadXml("<DocumentData></DocumentData>");
> > > XmlElement elem = doc.CreateElement(currentNodeName);
> > > elem.AppendChild(doc.CreateCDataSection(dataString ));
> > > doc.DocumentElement.AppendChild(elem);
> > > XPathNavigator newNav = doc.CreateNavigator();
> > >
> > > nav.InsertAfter(newNav);
> > >
> > >
> > > Regards,
> > > Eric.-
> > >
> >
> >
> >


Jun 2 '06 #7


ericms wrote:

And when I did the following :

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

Everything is fine except that the "less than" sign is replaced with
ampersand, lt, semicolon and the greater sign is replaced with ampersand, gt,
semicolon.


Simply do
writer.WriteCData(dataString);
do _not_ write out the <![CDATA]]> demiliters yourself, the writer will
add them directly when WriteCData is executed.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 2 '06 #8
I have tried it and the following did not work:
writer.WriteCData(dataString);
It did not add the <![CDATA]]> demiliters as you indicated.

I am using VisualStudio 2005, .NET 2.0.
Thanks,
Eric.-

"Martin Honnen" wrote:


ericms wrote:

And when I did the following :

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

Everything is fine except that the "less than" sign is replaced with
ampersand, lt, semicolon and the greater sign is replaced with ampersand, gt,
semicolon.


Simply do
writer.WriteCData(dataString);
do _not_ write out the <![CDATA]]> demiliters yourself, the writer will
add them directly when WriteCData is executed.

--

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

Jun 2 '06 #9
Hi Eric,

Can you describe how you determined if it worked or not? Are you listing an
output file or maybe you just look for the expected data through
XPathNavigator. As I explained before, in the context of XPathNavigator a
CDATA section will surface as Text plus the markup (ie. "<![CDATA[", "]]>")
will be missing from the observable value.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
I have tried it and the following did not work:
writer.WriteCData(dataString);
It did not add the <![CDATA]]> demiliters as you indicated.

I am using VisualStudio 2005, .NET 2.0.
Thanks,
Eric.-

"Martin Honnen" wrote:


ericms wrote:

> And when I did the following :
>
> using (XmlWriter writer = nav.AppendChild())
> {
> writer.WriteCData("<![CDATA[" + dataString + "]]>");
> }
>
> Everything is fine except that the "less than" sign is replaced with
> ampersand, lt, semicolon and the greater sign is replaced with
> ampersand, gt,
> semicolon.


Simply do
writer.WriteCData(dataString);
do _not_ write out the <![CDATA]]> demiliters yourself, the writer will
add them directly when WriteCData is executed.

--

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

Jun 2 '06 #10
When I am done, I do the following:

string dataOut = navigator.OuterXml;
textBox1.Text = dataOut;

I check the output in the content of TextBox. There is where I don't see
the <![CDATA]]> delimiters.

"Ion Vasilian" wrote:
Hi Eric,

Can you describe how you determined if it worked or not? Are you listing an
output file or maybe you just look for the expected data through
XPathNavigator. As I explained before, in the context of XPathNavigator a
CDATA section will surface as Text plus the markup (ie. "<![CDATA[", "]]>")
will be missing from the observable value.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
I have tried it and the following did not work:
writer.WriteCData(dataString);
It did not add the <![CDATA]]> demiliters as you indicated.

I am using VisualStudio 2005, .NET 2.0.
Thanks,
Eric.-

"Martin Honnen" wrote:


ericms wrote:
> And when I did the following :
>
> using (XmlWriter writer = nav.AppendChild())
> {
> writer.WriteCData("<![CDATA[" + dataString + "]]>");
> }
>
> Everything is fine except that the "less than" sign is replaced with
> ampersand, lt, semicolon and the greater sign is replaced with
> ampersand, gt,
> semicolon.

Simply do
writer.WriteCData(dataString);
do _not_ write out the <![CDATA]]> demiliters yourself, the writer will
add them directly when WriteCData is executed.

--

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


Jun 2 '06 #11
I know what my problem is. I should have done the following:

string dataOut = document.OuterXml;
textBox1.Text = dataOut;

I should have used the OuterXml of the Document, not the Navigator.


"ericms" wrote:
When I am done, I do the following:

string dataOut = navigator.OuterXml;
textBox1.Text = dataOut;

I check the output in the content of TextBox. There is where I don't see
the <![CDATA]]> delimiters.

"Ion Vasilian" wrote:
Hi Eric,

Can you describe how you determined if it worked or not? Are you listing an
output file or maybe you just look for the expected data through
XPathNavigator. As I explained before, in the context of XPathNavigator a
CDATA section will surface as Text plus the markup (ie. "<![CDATA[", "]]>")
will be missing from the observable value.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
I have tried it and the following did not work:
writer.WriteCData(dataString);
It did not add the <![CDATA]]> demiliters as you indicated.

I am using VisualStudio 2005, .NET 2.0.
Thanks,
Eric.-

"Martin Honnen" wrote:

>
>
> ericms wrote:
>
>
> > And when I did the following :
> >
> > using (XmlWriter writer = nav.AppendChild())
> > {
> > writer.WriteCData("<![CDATA[" + dataString + "]]>");
> > }
> >
> > Everything is fine except that the "less than" sign is replaced with
> > ampersand, lt, semicolon and the greater sign is replaced with
> > ampersand, gt,
> > semicolon.
>
> Simply do
> writer.WriteCData(dataString);
> do _not_ write out the <![CDATA]]> demiliters yourself, the writer will
> add them directly when WriteCData is executed.
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
>


Jun 2 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Xah Lee | last post: by
6 posts views Thread by Cade Perkins | last post: by
2 posts views Thread by C | last post: by
2 posts views Thread by Steveino | last post: by
1 post views Thread by Dariusz Tomoń | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.