Search Results

Search found 15718 results on 629 pages for 'xml'.

Page 2/629 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Encode double quotes inside XML element using LINQ to XML

    - by davekaro
    I'm parsing a string of XML into an XDocument that looks like this (using XDocument.Parse) <Root> <Item>Here is &quot;Some text&quot;</Item> </Root> Then I manipulate the XML a bit, and I want to send it back out as a string, just like it came in <Root> <Item>Here is &quot;Some text&quot;</Item> <NewItem>Another item</NewItem> </Root> However, what I am getting is <Root> <Item>Here is \"Some text\"</Item> <NewItem>Another item</NewItem> </Root> Notice how the double quotes are now escaped instead of encoded? This happens whether I use ToString(SaveOptions.DisableFormatting); or var stringWriter = new System.IO.StringWriter(); xDoc.Save(stringWriter, SaveOptions.DisableFormatting); var newXml = stringWriter.GetStringBuilder().ToString(); How can I have the double quotes come out as &quot; and not \"? UPDATE: Maybe this can explain it better: var origXml = "<Root><Item>Here is \"Some text&quot;</Item></Root>"; Console.WriteLine(origXml); var xmlDoc = System.Xml.Linq.XDocument.Parse(origXml); var modifiedXml = xmlDoc.ToString(System.Xml.Linq.SaveOptions.DisableFormatting); Console.WriteLine(modifiedXml); the output I get from this is: <Root><Item>Here is "Some text&quot;</Item></Root> <Root><Item>Here is "Some text"</Item></Root> I want the output to be: <Root><Item>Here is "Some text&quot;</Item></Root> <Root><Item>Here is "Some text&quot;</Item></Root>

    Read the article

  • Create XML File Using XML Schema

    - by metdos
    Is there any easy way to create at least a template XML file using XML Schema? My main interest is bounded by C++, but discussions of other programming languages are also welcome.By the way I also use QT framework.

    Read the article

  • save xml object so that elements are in sorted order in saved xml file

    - by scot
    Hi , I am saving a xml document object and it is saved in a xml file as shown below . <author name="tom" book="Fun-II"/> <author name="jack" book="Live-I"/> <author name="pete" book="Code-I"/> <author name="jack" book="Live-II"/> <author name="pete" book="Code-II"/> <author name="tom" book="Fun-I"/> instead i want to sort the content in document object so that when i persist the object it is saved by grouping authors then book name as below: <author name="jack" book="Live-I"/> <author name="jack" book="Live-II"/> <author name="pete" book="Code-I"/> <author name="pete" book="Code-II"/> <author name="tom" book="Fun-I"/> <author name="tom" book="Fun-II"/> I use apache xml beans..any ideas on how to achieve this? thanks.

    Read the article

  • remove xml declaration from the generated xml document using java

    - by flash
    String root = "RdbTunnels"; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element rootElement = document.createElement(root); document.appendChild(rootElement); OutputFormat format = new OutputFormat(document); format.setIndenting(true); XMLSerializer serializer = new XMLSerializer(System.out, format); serializer.serialize(document); gives the result as following <?xml version="1.0" encoding="UTF-8"?> <RdbTunnels/> but I need to remove the xml declaration from the output how can I do that

    Read the article

  • validating an XML schema with empty attributes

    - by AdRock
    I am having trouble validating my xml schema. I get these errors on the schema 113: 18 s4s-elt-invalid-content.1: The content of '#AnonType_user' is invalid. 164: 17 s4s-elt-invalid-content.1: The content of '#AnonType_festival' is invalid. Element 'sequence' is invalid, misplaced, or occurs too often. and becuase of those 2 errors, i am getting loads of the same error. This is becuase the attribute id of the festival tag may be empty becuase there is not data for that festival cvc-datatype-valid.1.2.1: '' is not a valid value for 'integer'. cvc-attribute.3: The value '' of attribute 'id' on element 'festival' is not valid with respect to its type, 'integer'. The lines in the schema causing the problems are <xs:element name="user"> <xs:complexType> <xs:attribute name="id" type="xs:integer"/> <xs:sequence> <xs:element ref="personal"/> <xs:element ref="account"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="festival"> <xs:complexType> <xs:attribute name="id" type="xs:integer" user="optional"/> <xs:sequence> <xs:element ref="event"/> <xs:element ref="contact"/> </xs:sequence> </xs:complexType> </xs:element> This is a snippet from my XML file. One user has a festival and the other doesn't <member> <user id="3"> <personal> <name>Skye Saunders</name> <sex>Female</sex> <address1>31 Anns Court</address1> <address2></address2> <city>Cirencester</city> <county>Gloucestershire</county> <postcode>GL7 1JG</postcode> <telephone>01958303514</telephone> <mobile>07260491667</mobile> <email>[email protected]</email> </personal> <account> <username>BigUndecided</username> <password>ea297847f80e046ca24a8621f4068594</password> <userlevel>2</userlevel> <signupdate>2010-03-26T09:23:50</signupdate> </account> </user> <festival id=""> <event> <eventname></eventname> <url></url> <datefrom></datefrom> <dateto></dateto> <location></location> <eventpostcode></eventpostcode> <coords> <lat></lat> <lng></lng> </coords> </event> <contact> <conname></conname> <conaddress1></conaddress1> <conaddress2></conaddress2> <concity></concity> <concounty></concounty> <conpostcode></conpostcode> <contelephone></contelephone> <conmobile></conmobile> <fax></fax> <conemail></conemail> </contact> </festival> </member> <member> <user id="4"> <personal> <name>Connor Lawson</name> <sex>Male</sex> <address1>12 Ash Way</address1> <address2></address2> <city>Swindon</city> <county>Wiltshire</county> <postcode>SN3 6GS</postcode> <telephone>01791928119</telephone> <mobile>07338695664</mobile> <email>[email protected]</email> </personal> <account> <username>iTuneStinker</username> <password>3a1f5fda21a07bfff20c41272bae7192</password> <userlevel>3</userlevel> <signupdate>2010-03-26T09:23:50</signupdate> </account> </user> <festival id="1"> <event> <eventname>Oxford Folk Festival</eventname> <url>http://www.oxfordfolkfestival.com/</url> <datefrom>2010-04-07</datefrom> <dateto>2010-04-09</dateto> <location>Oxford</location> <eventpostcode>OX19BE</eventpostcode> <coords> <lat>51.735640</lat> <lng>-1.276136</lng> </coords> </event> <contact> <conname>Stuart Vincent</conname> <conaddress1>P.O. Box 642</conaddress1> <conaddress2></conaddress2> <concity>Oxford</concity> <concounty>Bedfordshire</concounty> <conpostcode>OX13BY</conpostcode> <contelephone>01865 79073</contelephone> <conmobile></conmobile> <fax></fax> <conemail>[email protected]</conemail> </contact> </festival> </member> This is my schema <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:simpleType name="postcode"> <xs:restriction base="xs:string"> <xs:minLength value="6"/> <xs:maxLength value="8"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="telephone"> <xs:restriction base="xs:string"> <xs:minLength value="10"/> <xs:maxLength value="13"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="mobile"> <xs:restriction base="xs:string"> <xs:minLength value="11"/> <xs:maxLength value="11"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="password"> <xs:restriction base="xs:string"> <xs:minLength value="32"/> <xs:maxLength value="32"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="userlevel"> <xs:restriction base="xs:integer"> <xs:enumeration value="1"/> <xs:enumeration value="2"/> <xs:enumeration value="3"/> <xs:enumeration value="4"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="county"> <xs:restriction base="xs:string"> <xs:enumeration value="Bedfordshire"/> <xs:enumeration value="Berkshire"/> <xs:enumeration value="Bristol"/> <xs:enumeration value="Buckinghamshire"/> <xs:enumeration value="Cambridgeshire"/> <xs:enumeration value="Cheshire"/> <xs:enumeration value="Cleveland"/> <xs:enumeration value="Cornwall"/> <xs:enumeration value="Cumberland"/> <xs:enumeration value="Derbyshire"/> <xs:enumeration value="Devon"/> <xs:enumeration value="Dorset"/> <xs:enumeration value="Durham"/> <xs:enumeration value="East Ridings Of Yorkshire"/> <xs:enumeration value="Essex"/> <xs:enumeration value="Gloucestershire"/> <xs:enumeration value="Hampshire"/> <xs:enumeration value="Herefordshire"/> <xs:enumeration value="Hertfordshire"/> <xs:enumeration value="Huntingdonshire"/> <xs:enumeration value="Isle Of Man"/> <xs:enumeration value="Kent"/> <xs:enumeration value="Lancashire"/> <xs:enumeration value="Leicestershire"/> <xs:enumeration value="Lincolnshire"/> <xs:enumeration value="London"/> <xs:enumeration value="Middlesex"/> <xs:enumeration value="Norfolk"/> <xs:enumeration value="North Yorkshire"/> <xs:enumeration value="Northamptonshire"/> <xs:enumeration value="Northumberland"/> <xs:enumeration value="Nottinghamshire"/> <xs:enumeration value="Oxfordshire"/> <xs:enumeration value="Rutland"/> <xs:enumeration value="Shropshire"/> <xs:enumeration value="Somerset"/> <xs:enumeration value="South Yorkshire"/> <xs:enumeration value="Staffordshire"/> <xs:enumeration value="Suffolk"/> <xs:enumeration value="Surrey"/> <xs:enumeration value="Sussex"/> <xs:enumeration value="Tyne and Wear"/> <xs:enumeration value="Warwickshire"/> <xs:enumeration value="West Yorkshire"/> <xs:enumeration value="Westmorland"/> <xs:enumeration value="Wiltshire"/> <xs:enumeration value="Wirral"/> <xs:enumeration value="Worcestershire"/> <xs:enumeration value="Yorkshire"/> </xs:restriction> </xs:simpleType> <xs:element name="folktask"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" maxOccurs="unbounded" ref="member"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="member"> <xs:complexType> <xs:sequence> <xs:element ref="user" minOccurs="0" maxOccurs="unbounded"/> <xs:element ref="festival" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="user"> <xs:complexType> <xs:attribute name="id" type="xs:integer"/> <xs:sequence> <xs:element ref="personal"/> <xs:element ref="account"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="personal"> <xs:complexType> <xs:sequence> <xs:element ref="name"/> <xs:element ref="sex"/> <xs:element ref="address1"/> <xs:element ref="address2"/> <xs:element ref="city"/> <xs:element ref="county"/> <xs:element ref="postcode"/> <xs:element ref="telephone"/> <xs:element ref="mobile"/> <xs:element ref="email"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="name" type="xs:string"/> <xs:element name="sex" type="xs:string"/> <xs:element name="address1" type="xs:string"/> <xs:element name="address2" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="county" type="xs:string"/> <xs:element name="postcode" type="postcode"/> <xs:element name="telephone" type="telephone"/> <xs:element name="mobile" type="mobile"/> <xs:element name="email" type="xs:string"/> <xs:element name="account"> <xs:complexType> <xs:sequence> <xs:element ref="username"/> <xs:element ref="password"/> <xs:element ref="userlevel"/> <xs:element ref="signupdate"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="username" type="xs:string"/> <xs:element name="password" type="password"/> <xs:element name="userlevel" type="userlevel"/> <xs:element name="signupdate" type="xs:dateTime"/> <xs:element name="festival"> <xs:complexType> <xs:attribute name="id" type="xs:integer" user="optional"/> <xs:sequence> <xs:element ref="event"/> <xs:element ref="contact"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="event"> <xs:complexType> <xs:sequence> <xs:element ref="eventname"/> <xs:element ref="url"/> <xs:element ref="datefrom"/> <xs:element ref="dateto"/> <xs:element ref="location"/> <xs:element ref="eventpostcode"/> <xs:element ref="coords"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="eventname" type="xs:string"/> <xs:element name="url" type="xs:string"/> <xs:element name="datefrom" type="xs:date"/> <xs:element name="dateto" type="xs:date"/> <xs:element name="location" type="xs:string"/> <xs:element name="eventpostcode" type="postcode"/> <xs:element name="coords"> <xs:complexType> <xs:sequence> <xs:element ref="lat"/> <xs:element ref="lng"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="lat" type="xs:decimal"/> <xs:element name="lng" type="xs:decimal"/> <xs:element name="contact"> <xs:complexType> <xs:sequence> <xs:element ref="conname"/> <xs:element ref="conaddress1"/> <xs:element ref="conaddress2"/> <xs:element ref="concity"/> <xs:element ref="concounty"/> <xs:element ref="conpostcode"/> <xs:element ref="contelephone"/> <xs:element ref="conmobile"/> <xs:element ref="fax"/> <xs:element ref="conemail"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="conname" type="xs:string"/> <xs:element name="conaddress1" type="xs:string"/> <xs:element name="conaddress2" type="xs:string"/> <xs:element name="concity" type="xs:string"/> <xs:element name="concounty" type="xs:string"/> <xs:element name="conpostcode" type="postcode"/> <xs:element name="contelephone" type="telephone"/> <xs:element name="conmobile" type="mobile"/> <xs:element name="fax" type="telephone"/> <xs:element name="conemail" type="xs:string"/> </xs:schema>

    Read the article

  • Deserialize an XML file - an error in xml document (1,2)

    - by Lindsay Fisher
    I'm trying to deserialize an XML file which I receive from a vendor with XmlSerializer, however im getting this exception: There is an error in XML document (1, 2).InnerException Message "<delayedquotes xmlns=''> was not expected.. I've searched the stackoverflow forum, google and implemented the advice, however I'm still getting the same error. Please find the enclosed some content of the xml file: <delayedquotes id="TestData"> <headings> <title/> <bid>bid</bid> <offer>offer</offer> <trade>trade</trade> <close>close</close> <b_time>b_time</b_time> <o_time>o_time</o_time> <time>time</time> <hi.lo>hi.lo</hi.lo> <perc>perc</perc> <spot>spot</spot> </headings> <instrument id="Test1"> <title id="Test1">Test1</title> <bid>0</bid> <offer>0</offer> <trade>0</trade> <close>0</close> <b_time>11:59:00</b_time> <o_time>11:59:00</o_time> <time>11:59:00</time> <perc>0%</perc> <spot>0</spot> </instrument> </delayedquotes> and the code [Serializable, XmlRoot("delayedquotes"), XmlType("delayedquotes")] public class delayedquotes { [XmlElement("instrument")] public string instrument { get; set; } [XmlElement("title")] public string title { get; set; } [XmlElement("bid")] public double bid { get; set; } [XmlElement("spot")] public double spot { get; set; } [XmlElement("close")] public double close { get; set; } [XmlElement("b_time")] public DateTime b_time { get; set; } [XmlElement("o_time")] public DateTime o_time { get; set; } [XmlElement("time")] public DateTime time { get; set; } [XmlElement("hi")] public string hi { get; set; } [XmlElement("lo")] public string lo { get; set; } [XmlElement("offer")] public double offer { get; set; } [XmlElement("trade")] public double trade { get; set; } public delayedquotes() { } }

    Read the article

  • XML: How to reprepresent objects with multiple occurences?

    - by savras
    hi, i need to save objects that can occur multiple times. each object is marked with unique identifier. when it is serialized first time all its properties are written. after that only references are used. <actionHistory> <add> <figure id="1" xsi:type="point"> <position x="1" y="2" /> </figure> </add> <change> <target ref="1" /> <property>x</property> <value>3</value> </change> </actionHistory> element 'target' only references to point saved before, but it can contain definition of new figure as well. there is also figure class hierarchy involved. is there any way to express it using xml-schema? any suggestions how to improve code above will be also appreciated.

    Read the article

  • XML parsing design using xmlpp and C++

    - by shagv
    I would like to use an xml format similar to the following: <CONFIG> <PROFILE NAME="foobar"> <PARAM ID="0" NAME="Foo" CLASS="BaseParam"/> <PARAM ID="2" NAME="Bar" CLASS="StrIntParam"> <VALUE TYPE="STRING">some String</VALUE> <VALUE TYPE="INT">1234</VALUE> </PARAM> </PROFILE> </CONFIG> CONFIG contains a list of PROFILEs which contain a list of PARAMs which themselves can be any structure (to be defined in the future). The idea was to define classes that parsed each PARAM type and to keep track of which class to use in the PARAM's CLASS attribute. In code I have a config class that manages the list of profiles and a profile class that manages the list of params. I would like the profile class to handle additional param types (that inherit BaseParam) without modification to the profile class (or at the very least with minimal modification). First of all, is this design viable? If so, what are some ways I could use different param classes and have their creation at run-time be automatic (the profile class sees the CLASS attribute and knows which type to create)?

    Read the article

  • XML Reader or Linq to XML

    - by Nasser Hajloo
    I have a 150MB XML file which used asDB in my project. Currently I'm using XMLReader to read content from it. I want to know it is better to use XMLReader or LinqToXML for this scenario. Note that I'm searching for an item in this xmland display search result, soitcan be take along or just a moment.

    Read the article

  • Describe repeating XML nodes in W3C XML Schema?

    - by NotMyName
    I have an XML document like: <Root> <Bravo /> <Alpha /> <Charlie /> <Charlie /> <Delta /> <Foxtrot /> <Charlie /> </Root> The order of the nodes does not matter. Each node may appear zero or one times, except for Charlie. Charlie may appear zero, one, or arbitrarily many times. The straightforward way to express this in XSD is: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="Root"> <xsd:complexType> <xsd:all> <xsd:element name="Alpha" minOccurs="0" maxOccurs="1" /> <xsd:element name="Bravo" minOccurs="0" maxOccurs="1" /> <xsd:element name="Charlie" minOccurs="0" maxOccurs="unbounded" /> <xsd:element name="Delta" minOccurs="0" maxOccurs="1" /> <xsd:element name="Echo" minOccurs="0" maxOccurs="1" /> <xsd:element name="Foxtrot" minOccurs="0" maxOccurs="1" /> </xsd:all> </xsd:complexType> </xsd:element> </xsd:schema> But this does not work, because xsd:all does not allow for maxOccurs greater than 1. Since I cannot use xsd:all, what should I use?

    Read the article

  • C# .net How we valiadate a xml with Multiple xml-schemas

    - by allen8374
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:m0="http://www.MangoDSP.com/schema" xmlns:m1="http://www.onvif.org/ver10/schema"> <SOAP-ENV:Body> <m:CreateView xmlns:m="http://www.MangoDSP.com/mav/wsdl"> <m:View token=""> <m0:Name>View1</m0:Name> <m0:ProfileToken>AnalyticProfile1</m0:ProfileToken> <m0:IgnoreZone> <m0:Polygon> <m1:Point y="0.14159" x="0.12159"/> <m1:Point y="0.24159" x="0.34159"/> <m1:Point y="0.14359" x="0.94159"/> </m0:Polygon> </m0:IgnoreZone> <m0:SceneType>Outdoor</m0:SceneType> <m0:CustomParameters> <m0:CustomParameter> <m0:Name>ViewParam1</m0:Name> <m0:CustomParameterInt>0</m0:CustomParameterInt> </m0:CustomParameter> </m0:CustomParameters> <m0:SnapshotURI><!--This element is ignored for the create view request --> <m1:Uri>http://www.blabla.com</m1:Uri> <m1:InvalidAfterConnect>true</m1:InvalidAfterConnect> <m1:InvalidAfterReboot>true</m1:InvalidAfterReboot> <m1:Timeout>P1Y2M3DT10H30M</m1:Timeout> </m0:SnapshotURI> </m:View> </m:CreateView> </SOAP-ENV:Body> </SOAP-ENV:Envelope> xmlns:m="http://www.MangoDSP.com/mav/wsdl" as localfile:"ma.wsdl" xmlns:m0="http://www.MangoDSP.com/schema" as localfile:"MaTypes.xsd" how can i validate it.

    Read the article

  • XML Serialize and Deserialize Problem XML Structure

    - by Ph.E
    Camarades, I'm having the following problem. Caught a list Struct, Serialize (Valid W3C) and send to a WebService. In the WebService I receive, transform to a string, valid by the W3C and then Deserializer, but when I try to run it, always occurs error, saying that some objects were not closed. Any help? Sent Code: #region ListToXML private XmlDocument ListToXMLDocument(object __Lista) { XmlDocument _ListToXMLDocument = new XmlDocument(); try { XmlDocument _XMLDoc = new XmlDocument(); MemoryStream _StreamMem = new MemoryStream(); XmlSerializer _XMLSerial = new XmlSerializer(__Lista.GetType()); StreamWriter _StreamWriter = new StreamWriter(_StreamMem, Encoding.UTF8); _XMLSerial.Serialize(_StreamWriter, __Lista); _StreamMem.Position = 0; _XMLDoc.Load(_StreamMem); if (_XMLDoc.ChildNodes.Count > 0) _ListToXMLDocument = _XMLDoc; } catch (Exception __Excp) { new uException(__Excp).GerarLogErro(CtNomeBiblioteca); } return _ListToXMLDocument; } #endregion Receive Code: #region XMLDocumentToTypedList private List<T> XMLDocumentToTypedList<T>(string __XMLDocument) { List<T> _XMLDocumentToTypedList = new List<T>(); try { XmlSerializer _XMLSerial = new XmlSerializer(typeof(List<T>)); MemoryStream _MemStream = new MemoryStream(); StreamWriter _StreamWriter = new StreamWriter(_MemStream, Encoding.UTF8); _StreamWriter.Write(__XMLDocument); _MemStream.Position = 0; _XMLDocumentToTypedList = (List<T>)_XMLSerial.Deserialize(_MemStream); return _XMLDocumentToTypedList; } catch (Exception _Ex) { new uException(_Ex).GerarLogErro(CtNomeBiblioteca); throw _Ex; } } #endregion

    Read the article

  • [Python]Xml add a node from another xml document

    - by michele
    Hi, I have two xml file: 1)model.xml 2)projectionParametersTemplate.xml I want to extract from 1) Algorithm Node with his child and put it in 2) I have wrote this code but it doesn't function. from xml.dom.minidom import Document from xml.dom import minidom xmlmodel=minidom.parse("/home/michele/Scrivania/d/model.xml") xmltemplate=minidom.parse("/home/michele/Scrivania/d/projectionParametersTemplate.xml") for Node in xmlmodel.getElementsByTagName("Algorithm"): print "\nNode: "+str(Node) for Node2 in xmltemplate.getElementsByTagName("ProjectionParameters"): print "\nNode2: "+str(Node2) Node2.appendChild(Node) This is model.xml link text This is projectionParametersTemplate.xml link text Thanks a lot.

    Read the article

  • How often are comments used in XML documents?

    - by Jeffrey Sweeney
    I'm currently developing a web-based XML managing program for a client (though I may 'market' it for future clients). Currently, it reads an XML document, converts it into manageable Javascript objects, and ultimately spits out indented, easy to read XML code. Edit: The program would be used by clients that don't feel like learning XML to add items or tags, but I (or another XML developer) may use the raw data for quick changes without using an editor. I feel like fundamentally, its ready for release, but I'm wondering if I should go the extra mile and allow support for remembering (and perhaps making) comments before generating the resulting XML. Considering that these XML files will probably never be read without a program interpreting it, should I really bother adding support for comments? I'll probably be the only one looking at raw files, and I usually don't use comments for XML anyway. So, are comments common/important in most XML documents?

    Read the article

  • perl xml parser get xml content within xml

    - by user391986
    How can I use XMLParser to get the item-@url, item-@replace and item-"value inside" for the content as a string of the node where item-@cone="one"? <cstep> <item cone="one" url="http://google.com/{ccc}/cthree" replace="{ccc}"> <itemsub conesub="conesub"> <itemsubsub conesubsub="conesubsub" /> </itemsub> </item> <item cone="two" url="http://google.com/{ccc}/cthree" replace="{ccc}"> <itemsub conesub="conesub"> <itemsubsub conesubsub="conesubsub" /> </itemsub> </item> </cstep>

    Read the article

  • Parsing xml files locally from assets folder using XmlPullParser

    - by Randolphg
    Im trying to parse a local xml file that I place in my assets folder. I've been trying to do this for almost a week now. Here is my test xml file Test1 Test2 Test3 Test4 Test5 I keep getting the same error: W/System.err(22458): org.xmlpull.v1.XmlPullParserException: unexpected type (position:TEXT Code: public void xmlParser() throws XmlPullParserException, IOException, ParserConfigurationException, SAXException { Log.d("tag", "xmlParsing...."); Arithmetic arthm = new Arithmetic(); XmlPullParserFactory xmlPF = XmlPullParserFactory.newInstance(); xmlPF.setValidating(false); XmlPullParser xml = xmlPF.newPullParser(); InputStream raw = getApplication().getAssets().open("menu.xml"); xml.setInput(raw, null); xml.nextTag(); Log.d("tag", "start parsing...."); String elementText = null; String elemName = null; int nofTags = 0; while (xml.getEventType() != XmlPullParser.END_DOCUMENT) { Log.d("tag", "while(xml.next)..."); switch (xml.getEventType()) { case XmlPullParser.START_DOCUMENT: Log.d("tag", "while (xml.getEventType() != XmlPullParser.END_DOCUMENT)"); break; case XmlPullParser.START_TAG: Log.d("tag", " case XmlPullParser.START_TAG"); elementText = xml.getName(); Log.d("tag", "elementText = " + elementText); if (xml.getEventType() != XmlPullParser.END_TAG) { xml.nextTag(); } break; case XmlPullParser.TEXT: Log.d("tag", "case TEXT"); if (elementText.equals("menu") && xml.isWhitespace()) { Log.d("tag", "<" + elementText + ">"); arthm.menu_name = xml.getText(); Log.d("tag", "value " + xml.getText() + " added"); } else if (elementText.equals("item")) { arthm.description = xml.getText(); Log.d("tag", "value " + xml.getText() + " added"); } else if (elementText.equals("SUBCATEGORY NAME")) { arthm.subcategoryDesc.add(xml.getText()); Log.d("tag", "value " + xml.getText() + " added"); } else if (elementText.equals("SUBCATEGORY DESC")) { arthm.subcategoryName.add(xml.getText()); Log.d("tag", "value " + xml.getText() + " added"); } break; case XmlPullParser.END_TAG: Log.d("tag", "case END_TAG"); nofTags += 1; String tags = Integer.toString(nofTags); Log.d("tags", elementText + " number of tags" + tags); if (xml.nextTag() != XmlPullParser.START_TAG) { xml.next(); } break; case XmlPullParser.END_DOCUMENT: Log.d("tag", "case END_DOCUMENT"); break; default: break; } } Log.d("tag", "Success!"); } Thanks in advance.

    Read the article

  • Can we replace XML with JSON entirely?

    - by Saeed Neamati
    I'm sure lots of developers are familiar with XML and JSON, and they've used both of them. Thus no point in explaining what they are, and what is their purpose, even in brief. If we try to map their concepts, we can say (correct me if I'm wrong): XML tags are equivalent to JSON {} XML attributes are equivalent to JSON properties XML tag collection is equivalent to JSON [] The only thing I can think of, which doesn't exist in JSON, is XML Namespaces. The question is, considering this mapping, and considering that JSON is highly lighter in this mapping, can we see a world in future (or at least theoretically think of a world) without XML, but with JSON doing everything XML does? Can we use JSON everywhere XML is used? PS: Please note that I've seen this question. It's something entirely different from what I'm asking here. Thus please don't mention duplicate.

    Read the article

  • Loading a new instance of a class through XML not working quite right

    - by Thegluestickman
    I'm having trouble with XML and XNA. I want to be able to load weapon settings through XML to make my weapons easier to make and to have less code in the actual project file. So I started out making a basic XML document, something to just assign variables with. But no matter what I changed it gave me a new error every time. The code below gives me a "XML element 'Tag' not found", I added and it started to say the variables weren't found. What I wanted to do in the XML file as well, was load a texture for the file too. So I created a static class to hold my texture values, then in the Texture tag of my XML document I would set it to that instance too. I think that's were the problems are occuring because that's where the "XML element 'Tag' not found" error is pointing me too. My XML document: <XnaContent> <Asset Type="ConversationEngine.Weapon"> <weaponStrength>0</weaponStrength> <damageModifiers>0</damageModifiers> <speed>0</speed> <magicDefense>0</magicDefense> <description>0</description> <identifier>0</identifier> <weaponTexture>LoadWeaponTextures.ironSword</weaponTexture> </Asset> </XnaContent> My Class to load the weapon XML: public static class LoadWeaponXML { static Weapon Weapons; public static Weapon WeaponLoad(ContentManager content, int id) { Weapons = content.Load<Weapon>(@"Weapons/" + id); return Weapons; } } public static class LoadWeaponTextures { public static Texture2D ironSword; public static void TextureLoad(ContentManager content) { ironSword = content.Load<Texture2D>("Sword"); } } I'm not entirely sure if you can load textures through XML, but any help would be greatly appreciated.

    Read the article

  • Receive the Broadcast program with XML [on hold]

    - by bitmez4
    I have a channel publishing sites and I wanna get into the channel CNN broadcast program.. CNN broadcast the program here: (you can see in source - xml File) http://tvprofil.net/xmltv/data/cnn.info/weekly_cnn.info_tvprofil.net.xml How the data according to the time of withdrawal? For example: Now program: "bitmez's table" next program: "stack's table" in 30 minute Is this possible? UPDATE 1 // -I can take the XML data but to all of XML file- <?php if(!$xml=simplexml_load_file('http://tvprofil.net/xmltv/data/cnn.info/weekly_cnn.info_tvprofil.net.xml')){ trigger_error('XML file -- read error',E_USER_ERROR); } echo 'X-'; foreach($xml as $programme){ echo 'Now: '.$programme->title.' <br/>'; } ?>

    Read the article

  • Unit Testing XML independent of physical XML file

    - by RAbraham
    Hi, My question is: In JUnit, How do I setup xml data for my System Under Test(SUT) without making the SUT read from an XML file physically stored on the file system Background: I am given a XML file which contains rules for creation of an invoice. My job is to convert these rules from XMl to Java Objects e.g. If there is a tag as below in my XML file which indicates that after a period of 30 days, the transaction cannot be invoiced <ExpirationDay>30</ExpirationDay> this converts to a Java class , say ExpirationDateInvoicingRule I have a class InvoiceConfiguration which should take the XML file and create the *InvoicingRule objects. I am thinking of using StAX to parse the XML document within InvoiceConfiguration Problem: I want to unit test InvoiceConfiguration. But I dont want InvoiceConfiguration to read from an xml file physically on the file system . I want my unit test to be independent of any physical stored xml file. I want to create a xml representation in memory. But a StAX parser only takes FileReader( or I can play with the File Object)

    Read the article

  • XML deserialization doubling up on entities

    - by Nathan Loding
    I have an XML file that I am attempting to deserialize into it's respective objects. It works great on most of these objects, except for one item that is being doubled up on. Here's the relevant portion of the XML: <Clients> <Client Name="My Company" SiteID="1" GUID="xxx-xxx-xxx-xxx"> <Reports> <Report Name="First Report" Path="/Custom/FirstReport"> <Generate>true</Generate> </Report> </Reports> </Client> </Clients> "Clients" is a List<Client> object. Each Client object has a List<Report> object within it. The issue is that when this XML is deserialized, the List<Report> object has a count of 2 -- the "First Report" Report object is in there twice. Why? Here's the C#: public class Client { [System.Xml.Serialization.XmlArray("Reports"), System.Xml.Serialization.XmlArrayItem(typeof(Report))] public List<Report> Reports; } public class Report { [System.Xml.Serialization.XmlAttribute("Name")] public string Name; public bool Generate; [System.Xml.Serialization.XmlAttribute("Path")] public string Path; } class Program { static void Main(string[] args) { List<Client> _clients = new List<Client>(); string xmlFile = "myxmlfile.xml"; System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(List<Client>), new System.Xml.Serialization.XmlRootAttribute("Clients")); using (FileStream stream = new FileStream(xmlFile, FileMode.Open)) { _clients = xmlSerializer.Deserialize(stream) as List<Client>; } foreach(Client _client in _clients) { Console.WriteLine("Count: " + _client.Reports.Count); // This write "2" foreach(Report _report in _client.Reports) { Console.WriteLine("Name: " + _report.Name); // Writes "First Report" twice } } } }

    Read the article

  • Read XML Files using LINQ to XML and Extension Methods

    - by psheriff
    In previous blog posts I have discussed how to use XML files to store data in your applications. I showed you how to read those XML files from your project and get XML from a WCF service. One of the problems with reading XML files is when elements or attributes are missing. If you try to read that missing data, then a null value is returned. This can cause a problem if you are trying to load that data into an object and a null is read. This blog post will show you how to create extension methods to detect null values and return valid values to load into your object. The XML Data An XML data file called Product.xml is located in the \Xml folder of the Silverlight sample project for this blog post. This XML file contains several rows of product data that will be used in each of the samples for this post. Each row has 4 attributes; namely ProductId, ProductName, IntroductionDate and Price. <Products>  <Product ProductId="1"           ProductName="Haystack Code Generator for .NET"           IntroductionDate="07/01/2010"  Price="799" />  <Product ProductId="2"           ProductName="ASP.Net Jumpstart Samples"           IntroductionDate="05/24/2005"  Price="0" />  ...  ...</Products> The Product Class Just as you create an Entity class to map each column in a table to a property in a class, you should do the same for an XML file too. In this case you will create a Product class with properties for each of the attributes in each element of product data. The following code listing shows the Product class. public class Product : CommonBase{  public const string XmlFile = @"Xml/Product.xml";   private string _ProductName;  private int _ProductId;  private DateTime _IntroductionDate;  private decimal _Price;   public string ProductName  {    get { return _ProductName; }    set {      if (_ProductName != value) {        _ProductName = value;        RaisePropertyChanged("ProductName");      }    }  }   public int ProductId  {    get { return _ProductId; }    set {      if (_ProductId != value) {        _ProductId = value;        RaisePropertyChanged("ProductId");      }    }  }   public DateTime IntroductionDate  {    get { return _IntroductionDate; }    set {      if (_IntroductionDate != value) {        _IntroductionDate = value;        RaisePropertyChanged("IntroductionDate");      }    }  }   public decimal Price  {    get { return _Price; }    set {      if (_Price != value) {        _Price = value;        RaisePropertyChanged("Price");      }    }  }} NOTE: The CommonBase class that the Product class inherits from simply implements the INotifyPropertyChanged event in order to inform your XAML UI of any property changes. You can see this class in the sample you download for this blog post. Reading Data When using LINQ to XML you call the Load method of the XElement class to load the XML file. Once the XML file has been loaded, you write a LINQ query to iterate over the “Product” Descendants in the XML file. The “select” portion of the LINQ query creates a new Product object for each row in the XML file. You retrieve each attribute by passing each attribute name to the Attribute() method and retrieving the data from the “Value” property. The Value property will return a null if there is no data, or will return the string value of the attribute. The Convert class is used to convert the value retrieved into the appropriate data type required by the Product class. private void LoadProducts(){  XElement xElem = null;   try  {    xElem = XElement.Load(Product.XmlFile);     // The following will NOT work if you have missing attributes    var products =         from elem in xElem.Descendants("Product")        orderby elem.Attribute("ProductName").Value        select new Product        {          ProductId = Convert.ToInt32(            elem.Attribute("ProductId").Value),          ProductName = Convert.ToString(            elem.Attribute("ProductName").Value),          IntroductionDate = Convert.ToDateTime(            elem.Attribute("IntroductionDate").Value),          Price = Convert.ToDecimal(elem.Attribute("Price").Value)        };     lstData.DataContext = products;  }  catch (Exception ex)  {    MessageBox.Show(ex.Message);  }} This is where the problem comes in. If you have any missing attributes in any of the rows in the XML file, or if the data in the ProductId or IntroductionDate is not of the appropriate type, then this code will fail! The reason? There is no built-in check to ensure that the correct type of data is contained in the XML file. This is where extension methods can come in real handy. Using Extension Methods Instead of using the Convert class to perform type conversions as you just saw, create a set of extension methods attached to the XAttribute class. These extension methods will perform null-checking and ensure that a valid value is passed back instead of an exception being thrown if there is invalid data in your XML file. private void LoadProducts(){  var xElem = XElement.Load(Product.XmlFile);   var products =       from elem in xElem.Descendants("Product")      orderby elem.Attribute("ProductName").Value      select new Product      {        ProductId = elem.Attribute("ProductId").GetAsInteger(),        ProductName = elem.Attribute("ProductName").GetAsString(),        IntroductionDate =            elem.Attribute("IntroductionDate").GetAsDateTime(),        Price = elem.Attribute("Price").GetAsDecimal()      };   lstData.DataContext = products;} Writing Extension Methods To create an extension method you will create a class with any name you like. In the code listing below is a class named XmlExtensionMethods. This listing just shows a couple of the available methods such as GetAsString and GetAsInteger. These methods are just like any other method you would write except when you pass in the parameter you prefix the type with the keyword “this”. This lets the compiler know that it should add this method to the class specified in the parameter. public static class XmlExtensionMethods{  public static string GetAsString(this XAttribute attr)  {    string ret = string.Empty;     if (attr != null && !string.IsNullOrEmpty(attr.Value))    {      ret = attr.Value;    }     return ret;  }   public static int GetAsInteger(this XAttribute attr)  {    int ret = 0;    int value = 0;     if (attr != null && !string.IsNullOrEmpty(attr.Value))    {      if(int.TryParse(attr.Value, out value))        ret = value;    }     return ret;  }   ...  ...} Each of the methods in the XmlExtensionMethods class should inspect the XAttribute to ensure it is not null and that the value in the attribute is not null. If the value is null, then a default value will be returned such as an empty string or a 0 for a numeric value. Summary Extension methods are a great way to simplify your code and provide protection to ensure problems do not occur when reading data. You will probably want to create more extension methods to handle XElement objects as well for when you use element-based XML. Feel free to extend these extension methods to accept a parameter which would be the default value if a null value is detected, or any other parameters you wish. NOTE: You can download the complete sample code at my website. http://www.pdsa.com/downloads. Choose “Tips & Tricks”, then "Read XML Files using LINQ to XML and Extension Methods" from the drop-down. Good Luck with your Coding,Paul D. Sheriff  

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >