473,414 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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 6417
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Xah Lee | last post by:
what does it mean when a style tag gives something like the following? <style type="text/css" media="screen,projection">/*<!]>*/</style> is this standard? Xah xah@xahlee.org ∑...
6
by: Cade Perkins | last post by:
How can the CDATA ending delimiter "]]>" be represented within a CDATA section itself? Consider an XML document that is intended to contain an embedded, uninterpreted XML example. Generally,...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
2
by: C | last post by:
Hi, I have an XML doc as below <WebSRFTemplate Version="1" Type="SERVICE"> <Data> <Field Name="SERVICEStaticRoute2IPnetwork1"><!]></Field> </Data> </WebSRFTemplate>
2
by: Steveino | last post by:
Hello, Just wondering if anyone could shed any light on this, it's probably me just being silly... I have a dataset that I've used to create an XmlDataDocument, in order to apply XSL. The XSL...
1
by: soccerdad | last post by:
I've got a class hierarchy generated from a .xsd schema file using the XSD.EXE tool. One of the elements will have its "inner text" set to a CDATA block. The XSD.EXE tool exposed a "Value" property...
2
by: Pugi! | last post by:
Using AJAX I want to send some information from the server (php-page) as XML to the client. The contents can be very divers so I have to use XML instead of text. On one occasion the contents is...
18
by: sim.sim | last post by:
Hi all. i'm faced to trouble using minidom: #i have a string (xml) within CDATA section, and the section includes "\r\n": iInStr = '<?xml version="1.0"?>\n<Data><!]></Data>\n' #After i...
1
by: Dariusz Tomoñ | last post by:
Hi, I have got xml document with CDATA sections containing special characters like links to images. All Iwant is to display the content in my div section. I tried like this: protected...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.