Rectangle 27 2

XMLTextWriter is what you're looking for. You should avoid using any of the HTMLEncode methods (there are several) unless you're actually encoding your text for use in an HTML document. If you're encoding text for use in an XML document (including XHTML), you should use XMLTextWriter.

Something like this should do the trick:

StringWriter strWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(strWriter);
xmlWriter.WriteString('Your String Goes here, < and >, as well as other special chars will be properly encoded');
xmlWriter.Flush();

Console.WriteLine("XML Text: {0}", strWriter.ToString());

.net - Is there any built-in function in NET Framework which encodes a...

.net xml vb.net xps .net-3.5
Rectangle 27 6

If for some reason you don't want to create the WSDL file, the example below could be used to manually construct a SOAP HTTP request:

var url = Settings.Default.URL; //'Web service URL'
var action = Settings.Default.SOAPAction; //the SOAP method/action name

var soapEnvelopeXml = CreateSoapEnvelope();
var soapRequest = CreateSoapRequest(url, action);
InsertSoapEnvelopeIntoSoapRequest(soapEnvelopeXml, soapRequest);

using (var stringWriter = new StringWriter())
{
    using (var xmlWriter = XmlWriter.Create(stringWriter))
    {
        soapEnvelopeXml.WriteTo(xmlWriter);
        xmlWriter.Flush();
    }
}

// begin async call to web request.
var asyncResult = soapRequest.BeginGetResponse(null, null);

// suspend this thread until call is complete. You might want to
// do something usefull here like update your UI.
var success = asyncResult.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5));

if (!success) return null;

// get the response from the completed web request.
using (var webResponse = soapRequest.EndGetResponse(asyncResult))
{
    string soapResult;
    var responseStream = webResponse.GetResponseStream();
    if (responseStream == null)
    {
        return null;
    }
    using (var reader = new StreamReader(responseStream))
    {
        soapResult = reader.ReadToEnd();
    }
    return soapResult;
}

private static HttpWebRequest CreateSoapRequest(string url, string action)
{
    var webRequest = (HttpWebRequest)WebRequest.Create(url);
    webRequest.Headers.Add("SOAPAction", action);
    webRequest.ContentType = "text/xml;charset=\"utf-8\"";
    webRequest.Accept = "text/xml";
    webRequest.Method = "POST";
    return webRequest;
}

private static XmlDocument CreateSoapEnvelope()
{
    var soapEnvelope = new XmlDocument();
    soapEnvelope.LoadXml(Settings.Default.SOAPEnvelope); //the SOAP envelope to send
    return soapEnvelope;
}

private static void InsertSoapEnvelopeIntoSoapRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
    using (Stream stream = webRequest.GetRequestStream())
    {
        soapEnvelopeXml.Save(stream);
    }
}

Thanks you so much Matt. Guess I'll build on this and see how I can incorporate SOAP attachements in the request also. Thanks a lot.

i have mistake .hear.may help me?

c# - How can I call a SOAP Web Service without Adding Web Reference - ...

c# .net wcf soap soap-client
Rectangle 27 932

import sys
sys.stdout.flush()
sys.stdout

Comment from @fredmb who doesn't have the rep to comment: "The references in [this] answer seem to be python 2 documentation specific. The python 3 references are: docs.python.org/3/glossary.html#term-file-object docs.python.org/3/library/io.html

printing - How to flush output of Python print? - Stack Overflow

python printing flush
Rectangle 27 60

ob_flush sends an application-initiated buffer. There may be multiple nested ob_start()'s in any PHP script. ob_flush passes the current content to the upper layer.

PHP itself might (at its own discretion) buffer output. This depends on the back-end. But usually FastCGI has a socket buffer on its own. Therefore flush() needs to be invoked as well to send the current content to the web server.

And now the web server might itself implement another buffering scheme (mod_deflate or content filter), which you have no influence over. But this is seldom, as it needs to be configured specifically.

Use ob_flush and flush and use them in that order.

The important detail missing from this answer is the output_buffering configuration option, whose default value in production versions of php.ini is 4096. That means that when any PHP script starts, the first 4096 bytes of output get buffered (in a buffer flushable with ob_flush()). This is why it is necessary to use ob_flush() as well as flush(). Disabling output_buffering via php.ini or calling ob_end_clean() or ob_end_flush() at the start of the script removes this necessity.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

PHP buffer ob_flush() vs. flush() - Stack Overflow

php flush output-buffering
Rectangle 27 25

ob_flush flushes output buffers you created with a function like ob_start

flush flushes buffered output of the PHP script itself to its caller

PHP buffer ob_flush() vs. flush() - Stack Overflow

php flush output-buffering
Rectangle 27 202

Since Python 3.3, you can force the normal print() function to flush without the need to use sys.stdout.flush(); just set the "flush" keyword argument to true. From the documentation:

Print objects to the stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.

Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.

printing - How to flush output of Python print? - Stack Overflow

python printing flush
Rectangle 27 18

ob_flush() is a high-level flush. It flushes high-level buffers and puts all content in the low-level, internal buffers ready to send.

  • Note that the ob_ family of functions create stacks of buffers, so just blindly writing ob_flush() everywhere is indeed going to give you "strange results" if the code was written to take advantage of this stacking.

flush() is a low-level flush, instructing PHP to flush its internal, low-level data buffers.

Below that still, there will be socket-layer buffers; below that, there are network-layer buffers. And, at the lowest level, the queue of electrons going down the data cable.

PHP buffer ob_flush() vs. flush() - Stack Overflow

php flush output-buffering
Rectangle 27 954

import sys
sys.stdout.flush()
sys.stdout
import sys  print "this gets buffered" sys.stdout.flush() # this forces it to print # ... more lines of code here print "this still gets buffered" sys.stdout.flush()

Comment from @fredmb who doesn't have the rep to comment: "The references in [this] answer seem to be python 2 documentation specific. The python 3 references are: docs.python.org/3/glossary.html#term-file-object docs.python.org/3/library/io.html

printing - How to flush output of Python print? - Stack Overflow

python printing flush
Rectangle 27 176

You need to create a StringWriter, and pass that to the XmlWriter.

The string overload of the XmlWriter.Create is for a filename.

using (var sw = new StringWriter()) {
  using (var xw = XmlWriter.Create(sw)) {
    // Build Xml with xw.


  }
  return sw.ToString();
}

@Will: Rolled back your change. XmlTextWriter.Close() will flush to the stream, so want that to happen before extracting the string. (Little difference in this case, but prefer to do this consistently because flush semantics of *Writer and Stream classes is not always clearly documented.)

Just a comment for people using this. If you happen to omit the using() and instead declare your XmlWriter normally then make sure to call xw.Flush before you call sw.ToString() or else you may not get all content! (Obviously better to use the using brackets...)

Keep in mind that the following code gives CA2202 warning during code analysis, beacuse Dispose() method will be called twice on StringWriter object

c# - XmlWriter to Write to a String Instead of to a File - Stack Overf...

c# xml
Rectangle 27 123

Probably the exact details of em.flush() are implementation-dependent. In general anyway, JPA providers like Hibernate can cache the SQL instructions they are supposed to send to the database, often until you actually commit the transaction. For example, you call em.persist(), Hibernate remembers it has to make a database INSERT, but does not actually execute the instruction until you commit the transaction. Afaik, this is mainly done for performance reasons.

In some cases anyway you want the SQL instructions to be executed immediately; generally when you need the result of some side effects, like an autogenerated key, or a database trigger.

What em.flush() does is to empty the internal SQL instructions cache, and execute it immediately to the database.

Bottom line: no harm is done, only you could have a (minor) performance hit since you are overriding the JPA provider decisions as regards the best timing to send SQL instructions to the database.

if flush() sends data to the database? what happens if an exception is thrown after that? Will the entity manager rollback everything? even the data written in the first flush?

flush() sends SQL instructions to the database like INSERT, UPDATE etc. It will not send a COMMIT, so if you have an exception after a flush(), you can still have a complete rollback.

You can rollback the DB, but it will not rollback any changes to the objects, e.g., auto-incremented 'version', autogenerated ID, etc. Furthermore the entity manager will be closed after a rollback. Just beware that if you try to 'merge' the object to another session, the auto-incremented 'version' in particular may cause an OptimisticLockException.

Apart from triggering side effects, another reason to use flush() is if you want to be able to read the effects of an operation in the database using JPQL/HQL (e.g. in a test). JPA cannot use cached data when executing these queries, so only stuff that's actually in the DB will be read.

java - Correct use of flush() in JPA/Hibernate - Stack Overflow

java hibernate jpa transactions persistence
Rectangle 27 270

python -h

-u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x see man page for details on internal buffering relating to '-u'

python -u is the perfect solution

printing - How to flush output of Python print? - Stack Overflow

python printing flush
Rectangle 27 262

python -h

-u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x see man page for details on internal buffering relating to '-u'

printing - How to flush output of Python print? - Stack Overflow

python printing flush
Rectangle 27 108

See the example below. This will position your Footer to stick to bottom if the page has less content and behave like a normal footer if the page has more content.

* {
    margin: 0;
}
html, body {
    height: 100%;
}
.wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -155px; /* the bottom margin is the negative value of the footer's height */
}
.footer, .push {
    height: 155px; /* .push must be the same height as .footer */
}
<div class="wrapper">
  <p>Your website content here.</p>
  <div class="push"></div>
</div>
<div class="footer">
  <p>Copyright (c) 2008</p>
</div>

UPDATE: New version of Bootstrap demonstrates how to add sticky footer without adding a wrapper. Please see Jboy Flaga's Answer for more details.

Why are there two height property definitions in wrapper?

@HardlyNoticeable one is min-width to force the wrapper even if the content is less.

html - Bootstrap 3 Flush footer to bottom. not fixed - Stack Overflow

html css twitter-bootstrap footer
Rectangle 27 271

There is a simplified solution from bootstrap here (where you don't need to create a new class): http://getbootstrap.com/examples/sticky-footer-navbar/

you can see that you only need this CSS

/* Sticky footer styles
-------------------------------------------------- */
html {
  position: relative;
  min-height: 100%;
}
body {
  /* Margin bottom by footer height */
  margin-bottom: 60px;
}
.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  /* Set the fixed height of the footer here */
  height: 60px;
  background-color: #f5f5f5;
}
<html>
    ...
    <body>
        <!-- Begin page content -->
        <div class="container">
        </div>
        ...

        <footer class="footer">
        </footer>
    </body>
</html>

This (from the Bootstrap docs / examples) should be the accepted answer.

For me this does not work because my footer is rather tall. It's great if you just want a paragraph but mine has several columns - using this method, I end up with a margin under the footer when I go down to smaller sizes

This worked for me only when I removed the height attribute in the footer class.

Isnt this Bootstraps sticky footer solution? I dont think the OP meant this. For me, with a long page my footer appeared at the bottom of the screen but not at the bottom of the content (ie over the content). I had to change Position: absolute; to relative (in .footer class) for this to work.

This would be the correct answer if this topic did not have "not fixed" in the title...

html - Bootstrap 3 Flush footer to bottom. not fixed - Stack Overflow

html css twitter-bootstrap footer
Rectangle 27 10

I guess this is in relation to your previous question. The significant advantage of using output buffering is when it's used alongside data compression. If you're not using ob_gzhandler, there's little to gain. flush alone will just commit whatever output data is still on the server. With ob_start and its counterparts ob_flush, ob_end_clean and ob_end_flush, whatever is waiting to be compressed (look at flush and ob_flush as referring to different buckets - ob sends data to flush, flush sends data to browser - may not be accurate but that's the idea) will be wrapped up and sent to the client.

Thanks, the bucket analogy is a nice example.

PHP buffer ob_flush() vs. flush() - Stack Overflow

php flush output-buffering
Rectangle 27 64

Also as suggested in this blog one can reopen sys.stdout in unbuffered mode:

sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
stdout.write
print
UnsupportedOperation: IOStream has no fileno.

Whoops, Python 3 found out. It won't let me execute this piece of code!

printing - How to flush output of Python print? - Stack Overflow

python printing flush
Rectangle 27 75

XmlDocument doc = new XmlDocument(); 
using (XmlWriter writer = doc.CreateNavigator().AppendChild()) 
{ 
    // Do this directly 
   writer.WriteStartDocument(); 
   writer.WriteStartElement("root"); 
   writer.WriteElementString("foo", "bar"); 
   writer.WriteEndElement(); 
   writer.WriteEndDocument();
    // or anything else you want to with writer, like calling functions etc.
}

Apparently XpathNavigator gives you a XmlWriter when you call AppendChild()

Thanks! It was obvious to me that you'd be able to use XmlWriter as a builder for XmlDocument but I just couldn't find an easy way to do it so I ended up writing to buffer and parsing again. They could've made it a little easier to find.

Anyone know if the same is possible using xdocument/xelement (using .NET 3.5 so cant load directly from the memorystream)

Also note that, as written, the resulting XmlWriter will have a conformance level of Document, so if you do send it as the input to an XSL transform as input (and you're not creating a complete document), you can use new XmlDocument().CreateFragment().CreateNavigator() instead.

Note one drawback to this is that WriteRaw behaves differently for an XmlWriter based on XPathNavigator namely, it escapes output.

How to create a XmlDocument using XmlWriter in .NET? - Stack Overflow

.net xmldocument xmlwriter
Rectangle 27 210

Since Python 3.3, you can force the normal print() function to flush without the need to use sys.stdout.flush(); just set the "flush" keyword argument to true. From the documentation:

Print objects to the stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.

Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.

printing - How to flush output of Python print? - Stack Overflow

python printing flush
Rectangle 27 98

As Richard said, StringWriter is the way forward. There's one snag, however: by default, StringWriter will advertise itself as being in UTF-16. Usually XML is in UTF-8. You can fix this by subclassing StringWriter;

public class Utf8StringWriter : StringWriter
{
    public override Encoding Encoding
    {
         get { return Encoding.UTF8; }
    }
}

This will affect the declaration written by XmlWriter. Of course, if you then write the string out elsewhere in binary form, make sure you use an encoding which matches whichever encoding you fix for the StringWriter. (The above code always assumes UTF-8; it's trivial to make a more general version which accepts an encoding in the constructor.)

using (TextWriter writer = new Utf8StringWriter())
{
    using (XmlWriter xmlWriter = XmlWriter.Create(writer))
    {
        ...
    }
    return writer.ToString();
}

Jon, are you sure that writer is not being disposed more than once?

@rasx: It might be - but that won't matter.

c# - XmlWriter to Write to a String Instead of to a File - Stack Overf...

c# xml
Rectangle 27 302

A Session object is basically an ongoing transaction of changes to a database (update, insert, delete). These operations aren't persisted to the database until they are committed (if your program aborts for some reason in mid-session transaction, any uncommitted changes within are lost).

The session object registers transaction operations with session.add(), but doesn't yet communicate them to the database until session.flush() is called.

session.flush() communicates a series of operations to the database (insert, update, delete). The database maintains them as pending operations in a transaction. The changes aren't persisted permanently to disk, or visible to other transactions until the database receives a COMMIT for the current transaction (which is what session.commit() does).

session.commit()

flush() is always called as part of a call to commit() (1).

When you use a Session object to query the database, the query will return results both from the database and from the flushed parts of the uncommitted transaction it holds. By default, Session objects autoflush their operations, but this can be disabled.

#---
s = Session()

s.add(Foo('A')) # The Foo('A') object has been added to the session.
                # It has not been committed to the database yet,
                #   but is returned as part of a query.
print 1, s.query(Foo).all()
s.commit()

#---
s2 = Session()
s2.autoflush = False

s2.add(Foo('B'))
print 2, s2.query(Foo).all() # The Foo('B') object is *not* returned
                             #   as part of this query because it hasn't
                             #   been flushed yet.
s2.flush()                   # Now, Foo('B') is in the same state as
                             #   Foo('A') was above.
print 3, s2.query(Foo).all() 
s2.rollback()                # Foo('B') has not been committed, and rolling
                             #   back the session's transaction removes it
                             #   from the session.
print 4, s2.query(Foo).all()

#---
Output:
1 [<Foo('A')>]
2 [<Foo('A')>]
3 [<Foo('A')>, <Foo('B')>]
4 [<Foo('A')>]

Just one more thing: do you know whether calling commit() increases the memory used, or decreases it?

This is also false for db engines that don't support transactions such as myisam. As there is no ongoing transaction, flush has even less to distinguish itself from commit.

session.query()
session.flush()

Is it good or poor style to use flush() and commit(), or should I leave that up to Alchemy. I used flush() in some cases because subsequent queries needed to pick up new data.

autoflush
True

python - SQLAlchemy: What's the difference between flush() and commit(...

python sqlalchemy