w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How can I get XmlReader to read my XML data in C#
The problem in your code has nothing to do with XML - it's just the sample code which assumes there is a variable called OutputTextBlock. That suggests the demo code was written in the context of a WPF app rather than a console app. If you just change your code to: Console.WriteLine(output.ToString()); then you should be fine. However, I'd strongly recommend using LINQ to XML and XDocument instead. Reading an XML document is very simple: String xmlString = @"<?xml version='1.0'?> <!-- This is a sample XML document --> <Items> <Item>test with a child element <more/> stuff</Item> </Items>"; XDocument doc = XDocument.Parse(xmlString); You can then find specific elements in the document etc. Start on the LINQ to XML "root" pag

Categories : C#

Why xmlreader can't read something that xmlwriter wrote?
You're probably not writing to a unicode file which File.WriteAllText or a vanilla FileStream does not do. Instead use File.OpenWrite or FileStream combined with the StreamWriter(Stream steam, Encoding encoding) constructor to specify unicode. Sample: var path = @"C:Devsample.xml"; string xml; var mRows = 30; var mColumns = 50; var options = new XmlWriterSettings { Indent = true }; using (var stringWriter = new StringWriter()) { using (var writer = XmlWriter.Create(stringWriter, options)) { writer.WriteStartDocument(); writer.WriteStartElement("Board"); writer.WriteAttributeString("Rows", mRows.ToString()); writer.WriteAttributeString("Columns", mColumns.ToString()); writer.WriteEndElement(); writer.WriteEndDocument(); }

Categories : C#

Read XML file with XmlReader (PortableClassLibrary)
You can't just pass a path to a file on Silverlight or Windows Store- they have different ways to access persisted storage. You can use my PCL Storage library to provide a common way to do File I/O in Portable Class Libraries. I'd also recommend reading my post on How to make Portable Class Libraries work for you for some general advice on using PCLs.

Categories : Xml

Read XML-File correctly using XmlReader using C#
I would suggest you have a look at xml serializer. Datatables are a pain to work with, so you could create a "To-Do" class and display the properties of this class after clicking on the corresponding identifier (lets say name) in your combobox. The serialization might not be the problem here, it most likely got more to do with what you try to display in your combobox, and how that is linked to the rows of your datasets... Edit: I have two possible solutions. They are both buggy and ugly, but its the best one can do within the limits of your implementation. Number one: Make your dataset accessible by all methods in your class: public partial class Form1 : Form { private DataSet dataset; private DataTable datatable; public Form1() { You can then (after initializing it

Categories : C#

Read External XML - XmlReader, XmlDocument, Serialization
Consider using Linq To XML to query your XML document. You can select them as your entity types (e.g. "send the values to C# object"). At this point, you've effectively 'normalized' your data - you can work with these entities to do whatever computations you need, ship them off for persistence, or whatever you need to do.

Categories : C#

How do I inject a string to NetworkStream so that it can be read via XmlReader.ReadAsync in C#?
NetworkStream is a Stream so that means you can write any chunk of data into it, including XML strings. Of course, you have to do some conversion like: byte[] data = System.Text.Encoding.UTF8.GetBytes(longXmlString); networkSteram.Write(data);

Categories : C#

Nested Fragments - IllegalStateException "Can not perform this action after onSaveInstanceState"
Update: Quick and Dirty (Official) Solution I believe this is latest official solution from Google. However, the solution really doesn't scale very well. If you're not comfortable messing with queues, handlers and retained instance states yourself then this may be your only option... but don't say I didn't warn you! Android activities and fragments have support for a LoaderManager which can be used with AsyncTaskLoader. Behind the scenes loader managers are retained in precisely the same way as retained fragments. As such this solution does share a bit in common with my own solution below. AsyncTaskLoader is a partially pre-canned solution that does technically work. However, the API is extremely cumbersome; as I'm sure you'll notice within a few minutes of using it. My Solution Firstl

Categories : Java

How to perform AND operation in Mongodb for a query on nested array of objects
Instead of individual field values you can also use whole objects in find queries. Try: db.collection.find( { users: { "name":"foo", "status":"a" } }); This should return all documents where the users array includes an object (or is an object) which looks as described. But note that this doesn't work when the object has additional fields.

Categories : Mongodb

(solved) python perform transformation on nested(?) list values during a for loop
Sorry for this question, it was easy, I found my solution there: python store variable in function and use it later If any help, here's my new code: output = open('solution_AT.txt','a') if tet_i == None: output.write(str(target[0])) output.write(' ') else: names = [colors[i][0] for i in tg.tets[tet_i]] sorted_indices = sorted(enumerate(names), key=lambda (i, name): priority_list[name]) output.write(target[0], 'none', '0', 'none', '0', 'none', '0', 'none', '0') counting = 0 top = 0 for i, name in sorted(enumerate(names), key=lambda (i, name): priority_list[name]): VAR1 = (bcoords[i]*AT) VAR2 = int(((bcoords[i]*AT)/(1-top))*65535) output.write(',%s,%s' % (name, VAR2)) counting = counting + 1 top = top + VAR1

Categories : Python

taking mean of data read in 'error cannot perform reduce with flexible type' python
right is a string. np.asarray(some_string) returns an array with string dtype. NumPy's np.mean function raises a TypeError when passed an array of string dtype. In [29]: np.asarray('1 2 3') Out[29]: array('1 2 3', dtype='|S5') In [31]: np.mean(a) TypeError: cannot perform reduce with flexible type Instead, use np.genfromtxt or np.loadtxt to load an array from a text file: a = np.genfromtxt(filename, ...)

Categories : Python

How to use XMLReader
Check the post by Troy http://troybrant.net/blog/2010/09/simple-xml-to-nsdictionary-converter/ Also, There are plenty of examples out there which can get you started. Check out the answers here for a similar question: Xml parsing in iOS tutorial always good idea to code through some tutorials before actual implementation.

Categories : IOS

XMLReader is unkown
You need a reference to the System.Xml assembly (System.Xml.dll). I'm surprised it doesn't exist in the project by default, but you may have removed it. Note that namespaces and assemblies are different things - a using directive only imports the namespace so you can use simple names (e.g. XmlReader) without further qualification, but you still need the assembly reference as well, in the project settings. (As an aside, I'd personally avoid using XmlReader directly unless you really need to handle huge documents. I'd use LINQ to XML where possible - the XDocument, XElement classes etc. For those, you'll need a reference to the System.Xml.Linq assembly.)

Categories : C#

How the XmlReader works in C#
System.Xml.Linq.XDocument.Parse(string) will give you an XDocument. XDocument.Root will get you the root XElement of your document. I think you'll find this very easy to work with. You're trying to use the previous generation of XML tools in .NET - the newer XDocument, XElement, etc tools are much more accessible. sample code using System.Xml.Linq; ... var root = XDocument.Parse(xmlString).Root; var cars = root .ToAll("Car") .Select(car => new { Name = car.ToFirst("Name").Value, Speed = car.ToAll("Speed").Any() ? car.ToFirst("Speed").Value : null, Color = car.ToFirst("Color").Value, Engine = car.ToFirst("Engine").Value, Year = int.Parse(car.ToFirst("Year").Value) }) .ToList(); helper class public static class XmlHel

Categories : C#

XmlReader is too greedy
Found the answer in this question. The XmlReader has to be set to read a fragment only, not a document. using (var xmlReader = XmlReader.Create(_tcpReader, new XmlReaderSettings {ConformanceLevel = ConformanceLevel.Fragment})) { xmlReader.MoveToContent(); var xmlElement = (XElement) XNode.ReadFrom(xmlReader); // works! } Note that XElement.Load dies: reader is expected to be EOF after this operation.

Categories : C#

Getting attributes for XMLReader
Have a look at SimpleXML. Specifically the link to attributes(). This should help you get started. If you still have problems please include the php code you are useing. EDIT: As Sundar said simple xml is easier to use however if your xml file is large then the combination of XMLReader and simplexml will use less memory as only the current node is stored. while ($z->name === 'EBook') { $node = simplexml_import_dom($doc->importNode($z->expand(), true)); #print EAN echo $node->attributes()->EAN; ... $z->next('EBook'); } See how to use xmlreader in php

Categories : PHP

How do I read a nested dictionary in a Django template?
This is a generator function that will return each row in a loop: def next_row(data): for day,rooms in data.iteritems(): for room,times in rooms.iteritems(): for time in times: yield (day, room, time) Use it like this: for row in next_row(data): # do something with row

Categories : Python

Am I right to read a nested lua table as argument from C function?
int count = lua_len(L, -1); // how to get the member count of ignoreColor array int colors[count]; for (int i=0; i count; i++) { colors[i] = luaL_checkinteger(L, -1-i); } The code segment for this looks incorrect (never mind the missing comparision operator in the loop). The correct function for getting the table length is lua_objlen. It looks like you're trying to get the numbers out of 'ignoreColor' but you haven't place them on the stack first. As a result luaL_checkinteger(L, -1-i); ends up accessing the wrong indices on the stack. You probably want something closer to this for example: int count = lua_objlen(L, -1); std::vector<int> colors(count); for (int i = 0; i < count; lua_pop(L, 1)) { lua_rawgeti(L, 4, ++i); colors.push_back( luaL_checkinteger(L, -1) ); }

Categories : C++

How to XMLReader and Deserialize in java
Possible solution of using DOM or SAX parser. Try it JAXBContext jc = JAXBContext.newInstance( "add your class's full qualified class name here" ); Unmarshaller u = jc.createUnmarshaller(); Object o = u.unmarshal( xmlSource ); You can cast the Object o to your type I think. Please refer this. http://jaxb.java.net/nonav/2.2.4/docs/api/javax/xml/bind/Unmarshaller.html

Categories : Java

PHP XMLReader get all node names
I didn't get the chance to test it, but give this a try: $reader = new XMLReader(); $reader->open($input_file); $nodeList = array(); while ($reader->read()) { // We need to check if we're dealing with an Element if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'b') { // Let's inspect the node's content as well while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT) { // Saving the node to an auxiliar array array_push($nodeList, $reader->localName); } } } // Finally, let's filter the array $nodeList = array_unique($nodeList); Performance-wise, if the file is huge then XMLReader is the way to go since it only loads

Categories : PHP

How to extract elements with XMLReader
I got it working finally. What I didn't understand is that read() doesn't just move to the next element, it moves to the next TOKEN, which could be text, a closing tag, or any XML element. Here's the working code for future readers: $xml = new XMLReader; $xml->open('data.xml'); $xml->read(); // One read to skip the "everything" element while ($xml->read()) { if ($xml->nodeType == XMLReader::ELEMENT) { if ($xml->name == 'url') { $xml->read(); if ($xml->nodeType == XMLReader::TEXT) { print 'got url: ' . $xml->value.PHP_EOL; } }elseif ($xml->name == 'text') { $xml->read(); if ($xml->nodeType == XM

Categories : PHP

Advantage of XmlTextReader over XmlReader
XmlTextReader is old. It was introduced in .NET 1.0. The XmlReader type was just a base class. They added the static XmlReader.Create method in .NET 2.0. Since .NET 2.0, new XmlTextReader() has been deprecated.

Categories : Xml

PHP xmlReader: When to open and close
Comments below between /** */ /** * If you can, open it here. */ Foreach ($modelArray as $model)// there are 10000 models /** * If you open the reader here, you are doing 10000 network requests. * * BUT depends on your needs, if the url must be get from the model, you'll * have to connect here. */ if(!$reader->open($request_url)){ echo "Error"; break; } while ($reader->readToNext('Product'){ // There are 500 Products per model //do my node processing here. Grab nodes and add to mysql DB } /** * IF you opened the connection just before the while, THEN close it here. */ /** * return HERE!?? * You're just checking the first model then!! */ return array('msg' =>

Categories : PHP

how to read values from JSON nested in multiple arrays
use the following code: for(var i = 0; i < listEditions.length; i++) { var arrayItem=item.listEditions[i].listInsertion; //get colorType value alert(arrayItem[0].colorType); //get color value alert(arrayItem[0].color) } i think it will meet your demand.you can see the example:http://jsfiddle.net/rayhan/x2H5W/

Categories : Java

How do I parse XML from NetworkStream via ReadAsync of XmlReader in C#?
It seems that you are decoding the stream elsewhere then feeding it in chunks to XmlReader. Because each time, you're creating a new XmlReader for every chunk, after the first chunk, you'll be feeding broken Xml to a process that expects a well-formed document. Why not save a whole bunch of coding and heartache by reading the stream directly? using(var r = XmlReader.Create(myNetworkStream)) { //await r.ReadAsync() only returns false at the end of the document //so this loop will read the whole document while (await r.ReadAsync()) { switch (r.NodeType) { case XmlNodeType.Element: Console.WriteLine(r.LocalName); break; case XmlNodeType.Text: Console.WriteLine(await

Categories : C#

XmlReader can't parse XML with format?
Your xml has namespace daclared. You should consider it when parsing nodes. I suggest you to use Linq to XML: XNamespace qn = "http://schemas.microsoft.com/SQL/Notifications/QueryNotification"; XElement notification = XElement.Parse(z); var message = (string)notification.Element(qn + "Message"); // Custom

Categories : C#

Reading Child Nodes with XMLReader
Well if you still can build that array, your XML file is probably not that large :). Try to load the whole file with simplexml for example, you might be surprised that it does not consume that much memory. Anyway, if you still want to use XMLReader, I often suggest my XMLReader Iterator library that is able to iterate over an XMLReader to access elements, children and do stuff like turning fragments into SimpleXMLElements. The following is an example which is nearly identical to your example above: require('xmlreader-iterators.php'); // https://github.com/hakre/XMLReaderIterator/tree/master/build/include $xmlFile = "xmlreader-17262798.xml"; $reader = new XMLReader(); $reader->open($xmlFile); /* @var $itemIterator XMLReaderNode[] */ $itemIterator = new XMLElementIterator($reader, '

Categories : PHP

Why does XmlReader check for illegal characters when settings tell otherwise?
You need to pass settings to XmlReader.Create(Stream, XmlReaderSEttings) function if you want to customize settings. The Create function you use will use default settings as covered in Remarks section: An XmlReaderSettings object with default settings is used to create the reader. If you wish to specify the features to support on the created reader, use the overload that takes an XmlReaderSettings object as one of its arguments, and pass in an XmlReaderSettings object with the correct settings.

Categories : C#

Validating XML string using inline XML schema with XmlReader
You have to add an ValidationEventHandler String parameter=@"<HostName>Arasanalu</HostName> <AdminUserName>Administrator</AdminUserName> <AdminPassword>A1234</AdminPassword> <PlaceNumber>38</PlaceNumber>"; // Set the validation settings. XmlReaderSettings settings = new XmlReaderSettings(); settings.DtdProcessing= DtdProcessing.Parse; settings.ValidationType = ValidationType.Schema; settings.ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema | XmlSchemaValidationFlags.AllowXmlAttributes | XmlSchemaValidationFlags.ReportValidationWarnings | XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.ProcessSchemaLocation;

Categories : C#

Why does XmlReader.ReadInnerXmlAsync hang when reading ?
I found one solution. XmlDocument doc = new XmlDocument(); doc.Load(r.ReadSubtree()); doc.DocumentElement.OuterXml; Maybe someone will provide something more elegant.

Categories : C#

Write XmlReader XML to immediate window in Visual Studio?
Do you want to debug XmlReader? From my experience it's easier to give up. Dispite that you can call XDocument.Load(reader).ToString() what will read the reader to its end thus make it further unusable. However you can initialize a new reader from resulting document. To make it easier write a helper method.

Categories : C#

C# XmlReader ChildNodes 30GB File importing into SQL Server
I'm not sure but these links might help: https://wiki.openstreetmap.org/wiki/Osmconvert#Dispose_of_Ways_and_Relations_and_Convert_them_to_Nodes https://wiki.openstreetmap.org/wiki/Osmconvert#Writing_CSV_Files also useful: osmfilter, Osmosis Some options of osmconvert and osmfilter require a strictly ordered input file: first all nodes, then all ways, and then all relations. Within reach group the data should be sorted by id. Conversion and filtering will be faster if you use .o5m (or maybe .pbf) file format.

Categories : C#

django rest framework model serializers - read nested, write flat
The simplest thing that occurs to me is to override get_serializer_class() on your view for POST/PUT to return a modified serializer not specifying the depth parameter and using a PrimaryKeyRelatedField for your languages field.

Categories : Django

Reading Specific elements using XMLReader and adding values to a generic List
Are you having null values for Item1 or Item2 or is it that you see null values in the test list. The culprit seems to be your code which is in a way that, every time the traversed node is an XmlNodeType.Element, you are adding the object to the list. Based on the your switch; if element is of type Item1, then Item2 will be null in the test object and for Item2 type, Item1 will be null always. Also, if your code have more element types, then objects which have both values as null would be inserted into your test object.

Categories : C#

Read initially unknown number of N lines from file in a nested dictionary and start in next iteration at line N+1
You could use a dictionary to keep track of all the IDX columns and just add each line's IDX column to the appropriate list in the dictionary, something like: from collections import defaultdict import csv all_lines_dict = defaultdict(list) with open('your_file') as f: csv_reader = csv.reader(f) for line_list in csv_reader: all_lines_dict[line_list[3]].append(line_list) Csv reader is part of python standard library, and makes reading csv files easy. It will read each line as a list of its columns. This differs from your requirements because each key is not a dictionary of dictionaries but it is a list of the lines that share the IDX key.

Categories : Python

Struts 1.1 nested and in combination
Use <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> and the code will look like <c:choose> <c:when test="${element.method1 == true}"> <c:choose> <c:when test="${element.method2 == true}"> <span style="color:green;"><c:out value="${element.prop1}/></span> </c:when> <c:otherwise> <span style="color:red;"><c:out value="${element.prop1}/></span> </c:otherwise> </c:choose> </c:when> <c:otherwise> <span style="color:black;"><c:out value="${element.prop1}/></span> </c:otherwise> </c:choose>

Categories : Java

Python - how can i read in and read out so that other readers can read it for further pursing?
Off the top of my head: $ java -cp /var/tmp/Audio.jar Main.Boot | tee /var/tmp/log.log | python -u /var/tmp/consumer.py & $ tail -f /var/tmp/log.log I would also do the awk/grep stuff inside python instead of going through a subprocess.

Categories : Java

IF Condition Perform Query, Else Perform Other Query
Try: select coalesce(i.id, t.id) id from (SELECT COUNT(*) countterm FROM table WHERE term LIKE "term") c left join (SELECT id, date FROM table_a FORCE INDEX(id) JOIN table_b ON table_a.id = table_b.id WHERE term LIKE "term") i on countterm > 4000 left join (SELECT id, date FROM table_a FORCE INDEX(term) JOIN table_b ON table_a.id = table_b.id WHERE term LIKE "term" GROUP BY term HAVING COUNT = 1) t on countterm <= 4000 ORDER BY coalesce(i.date, t.date) LIMIT 100;

Categories : Mysql

JQuery selector for finding a nested span within a nested class is not working
I don't see any problem with your code at the moment, let's reformat it a bit: var tabs = $('.collapse').not('.in'); console.log("tabs.length: " + tabs.length); tabs.each(function () { var $this = $(this), thisErrors = $this.find('.field-validation-error'), thisId = '#' + $this.attr('id'); console.log("current tab ID: " + thisId); console.log("number of errors: " + thisErrors.length); if (thisErrors.length) { $(thisId).collapse('show'); } }); Or working fiddle: http://jsfiddle.net/Rq8y7/ Does it work now? And what's the debug message in console after you run above code?

Categories : Jquery

How can I bind data from nested List<> objects to nested ListView controls?
You can bind the datasource of your inner list view to a property of the items bound to your outer listview. However, to do that the inner listview as to be in the itemtemplate of the outer listview. See the code below and note the DataSource='<%# Eval("Labels_color") %>' attribute for the inner list view. <asp:ListView ID="ListView_Orp_Results" runat="server" ItemPlaceholderID="itemPlaceholder"> <LayoutTemplate> <div id="outer_result_container"> <div id="itemPlaceholder" /> </div> </LayoutTemplate> <ItemTemplate> <div id="result_photo">...</div> <div id="result_category">...</div> <div id="result_detector">...</div> <div id="inner_result_container" runat="server"

Categories : Asp Net

Parsing a flattly-written nested text template into a usable nested data structure for N levels
Replaces each ">" with a tab. Output is pretty much exactly as your brute force output. (file.txt is your template file as above) test = open("file.txt", "r") for line in test: print line.replace(">", " ") #print line

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.