Give some string of xml ( maybe one long unformatted line), what is quick
way to format into a indented string? TIA
--
William Stacey, MVP 7 2527
William,
Two tricks come to mind
a) XSLT
b) Recursive function with an string strIndent static variable that appends
itself with a space everytime it recurses.
- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl... Give some string of xml ( maybe one long unformatted line), what is quick way to format into a indented string? TIA
-- William Stacey, MVP
Hi,
The easiest is to create a XmlDocument with a single parent Node and add the
whole string as the InerXml of the node..
May be ..
XmlDoc.SelectSingleNode("ParentNode").InnerXml = You unformatted string;
then
XmlDoc.Save("New File Name");
This will give you a good fomatted XML..
Nirosh.
"Sahil Malik" <co*****************@nospam.com> wrote in message
news:el*************@TK2MSFTNGP15.phx.gbl... William,
Two tricks come to mind
a) XSLT b) Recursive function with an string strIndent static variable that
appends itself with a space everytime it recurses.
- Sahil Malik You can reach me thru my blog
http://www.dotnetjunkies.com/weblog/sahilmalik
"William Stacey [MVP]" <st***********@mvps.org> wrote in message news:eB**************@TK2MSFTNGP12.phx.gbl... Give some string of xml ( maybe one long unformatted line), what is
quick way to format into a indented string? TIA
-- William Stacey, MVP
Hmmm Champika,
Maybe William didn't want to see the XML tags in the output - atleast that
is what I assumed.
If he does want to see the tags, why not do a save from the original
XMLDocument? (Or stream if not save).
- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
"Champika Nirosh" <te**@test.lk> wrote in message
news:OH*************@tk2msftngp13.phx.gbl... Hi,
The easiest is to create a XmlDocument with a single parent Node and add the whole string as the InerXml of the node..
May be ..
XmlDoc.SelectSingleNode("ParentNode").InnerXml = You unformatted string;
then
XmlDoc.Save("New File Name");
This will give you a good fomatted XML..
Nirosh.
"Sahil Malik" <co*****************@nospam.com> wrote in message news:el*************@TK2MSFTNGP15.phx.gbl... William,
Two tricks come to mind
a) XSLT b) Recursive function with an string strIndent static variable that appends itself with a space everytime it recurses.
- Sahil Malik You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
"William Stacey [MVP]" <st***********@mvps.org> wrote in message news:eB**************@TK2MSFTNGP12.phx.gbl... > Give some string of xml ( maybe one long unformatted line), what is quick > way to format into a indented string? TIA > > -- > William Stacey, MVP > >
Probably an easier/faster way, but this works as a generic method:
public static string GetFormattedXML(string xml)
{
using (StringWriter sw = new StringWriter() )
{
XmlTextWriter xw = new XmlTextWriter(sw);
xw.Formatting = Formatting.Indented;
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(xml);
xmldoc.WriteTo(xw);
xw.Close();
return sw.ToString();
}
}
--
William Stacey, MVP
"Champika Nirosh" <te**@test.lk> wrote in message
news:OH*************@tk2msftngp13.phx.gbl... Hi,
The easiest is to create a XmlDocument with a single parent Node and add
the whole string as the InerXml of the node..
May be ..
XmlDoc.SelectSingleNode("ParentNode").InnerXml = You unformatted string;
then
XmlDoc.Save("New File Name");
This will give you a good fomatted XML..
Nirosh.
"Sahil Malik" <co*****************@nospam.com> wrote in message news:el*************@TK2MSFTNGP15.phx.gbl... William,
Two tricks come to mind
a) XSLT b) Recursive function with an string strIndent static variable that appends itself with a space everytime it recurses.
- Sahil Malik You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
"William Stacey [MVP]" <st***********@mvps.org> wrote in message news:eB**************@TK2MSFTNGP12.phx.gbl... Give some string of xml ( maybe one long unformatted line), what is quick way to format into a indented string? TIA
-- William Stacey, MVP
Very correct..
This, I expected you to do..
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:ul**************@TK2MSFTNGP15.phx.gbl... Probably an easier/faster way, but this works as a generic method:
public static string GetFormattedXML(string xml) { using (StringWriter sw = new StringWriter() ) { XmlTextWriter xw = new XmlTextWriter(sw); xw.Formatting = Formatting.Indented; XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(xml); xmldoc.WriteTo(xw); xw.Close(); return sw.ToString(); } }
-- William Stacey, MVP
"Champika Nirosh" <te**@test.lk> wrote in message news:OH*************@tk2msftngp13.phx.gbl... Hi,
The easiest is to create a XmlDocument with a single parent Node and add the whole string as the InerXml of the node..
May be ..
XmlDoc.SelectSingleNode("ParentNode").InnerXml = You unformatted string;
then
XmlDoc.Save("New File Name");
This will give you a good fomatted XML..
Nirosh.
"Sahil Malik" <co*****************@nospam.com> wrote in message news:el*************@TK2MSFTNGP15.phx.gbl... William,
Two tricks come to mind
a) XSLT b) Recursive function with an string strIndent static variable that appends itself with a space everytime it recurses.
- Sahil Malik You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
"William Stacey [MVP]" <st***********@mvps.org> wrote in message news:eB**************@TK2MSFTNGP12.phx.gbl... > Give some string of xml ( maybe one long unformatted line), what is
quick > way to format into a indented string? TIA > > -- > William Stacey, MVP > >
> Very correct.. This, I expected you to do..
Not sure how to read that Champika? :-) To be clear, I meant there is
probably and easier way then what I posted. Also during the time waiting
for reply, I stated playing so just wanted to post this back. Was not
trying to step on any posts. Cheers!
--
William Stacey, MVP
Hi William,
I think your code is fine. That might be the simplest way that I can
thought. Cheers!
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights." This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Craig Thomson |
last post by:
Do people generally try and output nicely formatted html from their
scripts?
I have been trying to, with variable indenting for tables etc. It
makes it easier to see the html and perhaps debug...
|
by: Mark |
last post by:
How do I output formatted numerical data to an external (text) file. At
a minimum I want to specify the number of decimal places to print.
Ideally I'd like the type of control the fortran FORMAT...
|
by: Matthew Thorley |
last post by:
Greetings, perhaps someone can explain this. I get to different styles
of formatting for xmla and xmlb when I do the following:
from elementtree import ElementTree as et
xmla =...
|
by: Joe C |
last post by:
I've written a console application and would like to isolate all screen
output so that it will be easier to migrate the code to a GUI-type platform
without modification to the base code. As a...
|
by: Jason Heyes |
last post by:
I am starting to worry about the performance of formatted read/write
operations on data-redundant objects in my program.What can I do to improve
this performance should it become an issue?
...
|
by: Steven T. Hatton |
last post by:
I'm still not completely sure what's going on with C++ I/O regarding the
extractors and inserters. The following document seems a bit inconsistent:...
|
by: Magix |
last post by:
Hi,
I want to use fprintf to write to a file. My question about the formatted
output
How can I format so that I can allocate certain width for each %s
(Left-aignlied) ?
Example:
fprintf("%s...
|
by: Craig Petrie |
last post by:
Hi,
I have a large table in Word 2003 that has formatted text in the cells and
wish to read and convert a cells formatted contents to html output via
vb.net code. The formatting contains the...
|
by: Jojo |
last post by:
Hi all,
I was wondering how I can perform formatted output with C++ strings. For
example, suppose I have in plain C:
sprintf(C_string, "%5.2f %6d");
How can I do such a thing with C++...
|
by: keith |
last post by:
I've been beating my head against this for a little while, so perhaps
someone can help me out here? The code below should output exactly as
follows (the hex data lines up in a fixed font):
DATA...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
| |