f



get a xml node as-it-is

i hve a xml like this:
<Students>
  <Student name = "arun1" number="6">
  <Student name = "arun2" number="7">
  <Student name = "arun3" number="8">
  <Student name = "arun4" number="9">
....
....
....
</Students>

i need to build a new xml or a string from this with few student
nodes.... some thing like this..

<Student>
  <Student name = "arun2" number="7">
  <Student name = "arun3" number="8">
</Student>

by selecting only the two nodes.........

is there any api which should return some thing like this ????
"<Student name = "arun2" number="7">"


Thanks
ArunDhaJ
0
arundhaj (21)
1/17/2008 7:20:44 AM
comp.text.xml 8781 articles. 0 followers. Post Follow

1 Replies
446 Views

Similar Articles

[PageSpeed] 25

ArunDhaJ wrote:
> i hve a xml like this:
> <Students>
>   <Student name = "arun1" number="6">

That is not well-formed, you need e.g.
   <Student name = "arun1" number="6"></Student>
>   <Student name = "arun2" number="7">
>   <Student name = "arun3" number="8">
>   <Student name = "arun4" number="9">
> ...
> ...
> ...
> </Students>
> 
> i need to build a new xml or a string from this with few student
> nodes.... some thing like this..
> 
> <Student>
>   <Student name = "arun2" number="7">
>   <Student name = "arun3" number="8">
> </Student>
> 
> by selecting only the two nodes.........
> 
> is there any api which should return some thing like this ????
> "<Student name = "arun2" number="7">"

Use an XSLT stylesheet for instance that copies what you want to copy:
   <xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
     <xsl:output method="xml"/>
     <xsl:template match="Students">
       <xsl:copy>
         <xsl:copy-of select="Student[@name = 'arun2' or @name = 'arun3']"/>
       </xsl:copy>
     </xsl:template>
   </xsl:stylesheet>

You could as well use DOM programming to load the original document, the 
  delete the Student elements you are not interested in and then save 
the DOM back.

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
0
mahotrash (2052)
1/17/2008 1:54:14 PM
Reply:

Similar Artilces:

XML DOM: XML/XHTML inside a text node
In my program, I get input from the user and insert it into an XHTML document. Sometimes, this input will contain XHTML, but since I'm inserting it as a text node, xml.dom.minidom escapes the angle brackets ('<' becomes '&lt;', '>' becomes '&gt;'). I want to be able to override this behavior cleanly. I know I could pipe the input through a SAX parser and create nodes to insert into the tree, but that seems kind of messy. Is there a better way? Thanks. On Thu, 2 Nov 2005 noahlt@gmail.com wrote: > In my program, I get input from the us...

XML or not XML?
I am developing a simple MySQL database editor, and am looking into creating an PHP/AJAX app as the GUI. A lot of this in new ground, and much more is dusting off things I haven't used in a while. My question though involves whether or nor to employ XML. I did some XML a few years back, but don't typically bother anymore. As I see it XML is great when I need to have an app with a standard data presentation that other developers can easily interface. I.E. like a bank statement that may feed a variety of applications developed by a variety of clients. However, if I am develo...

To XML or not to XML?
Ok, it has been a while since I've needed to make an involved web page. Coming back on the scene now is a bit confusing, what with all the cool stuff to use like XML, PHP, MySQL, etc... So here is my question. I'm in search of a good dynamic way to generate web pages which separates content from presentation. I am seeking to create a web site that, to put it succinctly, has a list of users and sets of information corresponding to each user. I am familiar with how to do this using PHP, MySQL, and regular old HTML. I maintain the user database in MySQL and dynamically present it and th...

XML to XML
I have a gnucash file that I'm trying to transform into an identical XML file without the invoices. I've been at this for a while now. The gnucash file is in XML and the element I'm looking into is: <gnc:transaction> I want to ignore those that contain <slot:key>gncInvoice</slot:key> which is a child of slot which is a child of slots which is a child of transactions. Any help you're willing to provide would be greatly appreciated. Thanks. Classic application for XSLT. Start with the identity transformation, then add a template which matches the ones you want to treat specially and yields no output. From your description that would be match="gnc:transaction[transactions/slots/slot/slot:key='gncInvoice']" with the namespaces declared appropriately in the stylesheet. (That looks like a somewhat unlikely markup design to me, but since I haven't played with gnucash at all I'm taking your word for it.) -- () ASCII Ribbon Campaign | Joe Kesselman /\ Stamp out HTML e-mail! | System architexture and kinetic poetry Actually, from the Relax-NG schema for gnucash, it looks like it should be more like "gnc:transaction[trn:slots/slot/slot:key='gncInvoice']" with gnc:, trn:, and slot: all bound to the appropriate namespace URIs. The fact that some of their elements -- eg <slot> -- aren't in any namespace is probably left over from a pre-namespaces initial design, as is their now-brok...

get xml attribut from a xml
hi... i load some xml into my program but now need to do complex thing whit it, and cant figure out... in my xml i got plany items..... but i want to get all items which have gril on "ok" in the data content... is that possible and how ? need help <items itemno=3D"1234"> <name>kartofler</name> <data> <data content=3D"gril">ok</data> <data content=3D"ovn">280 grader</data> <data content=3D"kogning">30 min p=E5 plus</meta> </data> ...

embedding xml in xml as non-xml :)
Hi all, I have an application that logs in xml. Assume <xmlLog></xmlLog>. In this element the app logs anything it gets from foreign hosts. Now if the host sends xml data, the structure of the document changes. ie. <xmlLog><somTag></somTag></xmlLog>. This will cause problems with my log reader, because it assumes that <xmlLog/> contains non-xml data. My question is, is there a way to treat the data in the <xmlLog/> element as non xml data. Something I can do that would treat anything this element contains as a literal? Any help or suggestions would be greatly appreciated. Regards, Mark Mark Van Orman <mark@icsaccess.com> wrote: > Hi all, > > I have an application that logs in xml. > > Assume <xmlLog></xmlLog>. In this element the app logs > anything it gets from foreign hosts. Now if the host sends xml > data, the structure of the document changes. ie. > <xmlLog><somTag></somTag></xmlLog>. This will cause problems > with my log reader, because it assumes that <xmlLog/> contains > non-xml data. > > My question is, is there a way to treat the data in the > <xmlLog/> element as non xml data. Something I can do that > would treat anything this element contains as a literal? > > Any help or suggestions would be greatly ap...

Get XML values from nodes and child nodes
Hi everybody. My XML file is: <Locatore> <NumeroProgressivo>001</NumeroProgressivo> <CodiceFiscale>CSTNDA69P90H523R</CodiceFiscale> <PersoneFisiche> <Cognome>CAST</Cognome> <Nome>NADIR</Nome> <Sesso>F</Sesso> <DataNascita>10091979</DataNascita> <ComuneNascita>RONCA</ComuneNascita> <ProvinciaNascita>BL</ProvinciaNascita> </PersoneFisiche> </Locatore> <Locatore> <NumeroProgressivo>002</NumeroProgressivo> <CodiceFiscale>PRSGRI74L29F443L</CodiceFiscale> <PersoneFisiche> <Cognome>PERISSI</Cognome> <Nome>IGOR</Nome> <Sesso>M</Sesso> <DataNascita>29071970</DataNascita> <ComuneNascita>MONTE</ComuneNascita> <ProvinciaNascita>SA</ProvinciaNascita> </PersoneFisiche> </Locatore> I need to get in ONE RECORD, both node value and his child nodes values, like this 001 | CSTNDA69P90H523R | CAST | NADIR | F | 10091979 | RONCA | BL 002 | PRSGRI74L29F443L | PERISSI | IGOR | M | 29071970 | MONTE | SA ..... With this: SELECT X.valore.query('NumeroProgressivo').value('.', 'VARCHAR(20)') as NumeroProgressivo, X.valore.query('CodiceFiscale').value('.', 'VARCHAR(16)') as CodiceFiscale FROM Tbulk CROSS APPLY Tbulk.nodes('Fornitura/Documento/S...

Getting all nodes and node details from xml using xquery
Hi, I haev the following code: DECLARE @x xml SET @x=' <Root> <row id="1"><name>Larry</name><oflw>some text</oflw></row> <row id="2"><name>Joe</name></row> <row id="3" /> </Root> ' exec sp_xml_preparedocument @idoc OUTPUT, @x SELECT * FROM OPENXML(@idoc, '/Root') This gives the following details id parentid nodetype localname prefix namespaceuri datatype pr...

file command: "XML document text" vs "XML document text"
I've just used the file command on four files of RDF-XML with the following output: augtfidf.rdf: XML document text kyoto.rdf: XML document text stuff.rdf: XML document text tfidf.rdf: XML document text What does it mean that one of them has an extra space between "XML" and "document"? -- The kid's a hot prospect. He's got a good head for merchandising, an agent who can take you downtown and one of the best urine samples I've seen in a long time. [Dead Kennedys t-shirt] On 16.10.2012 16:06, Adam Funk wrote: > I've just used the file command on four files of RDF-XML with the > following output: > > augtfidf.rdf: XML document text > kyoto.rdf: XML document text > stuff.rdf: XML document text > tfidf.rdf: XML document text > > What does it mean that one of them has an extra space between "XML" > and "document"? Hard to tell without further information. What does file *.rdf | od -c show you? Janis Janis Papanagnou wrote: > On 16.10.2012 16:06, Adam Funk wrote: >> I've just used the file command on four files of RDF-XML with the >> following output: >> >> augtfidf.rdf: XML document text >> kyoto.rdf: XML document text >> stuff.rdf: XML document text >> tfidf.rdf: XML document text >> >> What does it mean that one ...

Non-XML tagged value text to XML
I would like to use XSLT to translate some tagged value text to XML elements like this: Input Doc: <data>x=1.234 y=ABC z="Hello World"</data> Output Doc: <x>1.234</value> <y>ABC</y> <z>&quot;Hello World&quot;</z> Is XSLT up to the task? What would it look like? Most of the XSLT string processing code I've seen looks very verbose - can't be too efficient. mikea_59 wrote: > I would like to use XSLT to translate some tagged value text to XML > elements like this: > > Input Doc: > > <data>x=1.234 y=ABC z="Hello World"</data> > > Output Doc: > > <x>1.234</value> > <y>ABC</y> > <z>&quot;Hello World&quot;</z> > > Is XSLT up to the task? What would it look like? Most of the XSLT > string processing code I've seen looks very verbose - can't be too > efficient. Using XSLT 2.0 you can do that with regular expression matching as follows: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" encoding="UTF-8" indent="yes" /> <xsl:template match="/"> <results> <xsl:apply-templates /> </results> </xsl:template> <xsl:template match="data"...

Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser)
Hello Usenet. I'm subject to some confusion with XML and UTF8. I'm working with XML-Simple and I try to decode some XML with with german umlauts (ISO-8859-1). The first XML line declared the encoding correct (see code below). But I'm getting different results using XML-Simple with the default XML parser named XML::Sax and a second parser named XML::Parser. The following code tries to decode the mini XML file and prints the UTF8 flags of the resulting strings. Can someone run this code on his machine and post the results? Thanks. The results on my machine are this: ���ä...

xml wrongly views as text extracted from the xml tags
we have a java framework, where we feed a request xml. this request xml is forwarded through the framework, tomcat and axis, for the backend processing, and the processing results are again received by the internet explorer, after they are transformed with an xslt by the framework. now the problem that we are facing is like - the explorer extracts the text inside all xml tags of the response xml and shows it as simple text. but, if you view the source of the 'text', it will show it all as well-formed xml. moreover, if you save the source as an xml file, and again open it through internet explorer, it will show the xml in proper way. i have tried using firefox, processing with xml spy, but with same results... has somebody experienced similar problem before??? i wonder what can be wrong in this case, and would be thankful for any pointers as to what can be the cause and solution to this. Thanks in advance, Shreyas Hi all, Finally i got what was the problem. it was because the response xml contained a <Title> </Title> tag in it. and dont know why/how, but IE was treating it as an HTML tag. i noticed that the browser window title was indeed "Mr" which is the text enclosed by the Title element. one more weird thing i noticed was that if i moved the <xsl:apply-templates> line for the tag downwords after one more template application, it was showing the xml properly alongwith the <Title> element, and not treating it as an HTML tag...

getting text out of an xml string
Yo, So I have almost convinced a small program to do what I want it to do. One thing remains (at least, one thing I know of at the moment): I am converting xml to some other format, and there are strings in the xml like this. The python: elif v == "content": print "content", a.childNodes[0].nodeValue what gets printed: content \u3c00note xml:space="preserve"\u3e00see forms in red inbox \u3c00/note\u3e00 what this should say is "see forms in red inbox" because that is what the the program whose xml file i am trying to convert, prop...

XML to XML conversion
Hello, I vageuly remember a standard that allowed for an XML document using one tag vocabulary to be translated to a diffirent XML document using a diffirent tag vocabulary using the information provided in a kind of dictionary XML pointed to in an URL present in the original XML file. I am very interested in trying it out for various applications, but I can't find anything on the internet about it, since I don't remember it's name, only the general appearance. Can anyone help me with this? What I remember, approximately: The idea is that you have one XML file, in which the namespace is defined in the standard way, using an URI. The URI, however, is pointing to an online XML file. For example: <x xmlns:abc="http://www.server.org/dictionary.xml"> <abc:one>orange</abc:one> </x> This dictionary.xml then contains, for example: <root> <one> <format1>1</format1> <format2>uno</format2> <format3>ena</format3> <format4>ein</format4> </one> </root> So a program wishing to convert the original XML to, say format2, would end up with the following XML: <x> <uno>orange</uno> </x> What I remember is that this dictionary trick was mainly used to allow diffirent software to be able to interpret the same XML file, without all of the software needing to be programmed for the same tag vocabulary. The program w...

[XML] Is there an XML group?
Hi, I've typed an XML source which calls a CSS source, the result should be a page displayed in IE6, instead I see the XML source. That's pretty logical since there a no XHTML tags for IE6 to interpret. I'm looking for a discussion group like'comp.lang.xml' but I can't find one. Please help me. The first task is to see the Blue Jay. universalbitmapper wrote: > I'm looking for a discussion group like'comp.lang.xml' but I can't find > one. There's a comp.text.xml, which might be what you're looking for. Note that I don't read it,...

xml from 2 xml
Hi to everybody, would I like to create a consequential xml from the elaboration of two files xml using xslt, but is it possible to give in input to a trasform 2 files xml? thanks for the possible answers I have already found from me the answer: the function document('file2.xml') matatu ha scritto: > Hi to everybody, > > would I like to create a consequential xml from the elaboration of two > files xml using xslt, but is it possible to give in input to a trasform > 2 files xml? > > thanks for the possible answers ...

Generate xml node tree from xmi (xml) help
Hi, I am using argouml ( really neat UML modeling tool) to create a model. I export the model to xmi format ( it's xml). My UML-diagram looks like this: Brand A | -------------------- | | | Brand B Brand C Brand D And Brand B, Brand C and Brand D can also have children and so on ......... I need to generate an xml file that can describe these relationships like: <MyModel> <Brand A> <Brand B> </Brand B> <Brand C> </Brand C> <Brand D> </Brand D> </Brand A> </MyModel> I am thinking of checking the children for root (Brand A) and generate TAGs for each node. Then I make the first node to the left (Brand B) the parent get all children for that one. Any one with hints on how I can do this in xslt. I need some sort of traversing to get the tree right? Regards, //Mikael -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ Mikael P wrote: > Hi, > > I am using argouml ( really neat UML modeling tool) to create a model. I > export the model to > xmi format ( it's xml). Try posting that XML . . Soren -- Fjern de 4 bogstaver i min mailadresse som er indsat for at hindre s... Remove the 4 letter word meaning "junk mail" in my mail address. ...

extracting text from an XML node
Hi, suppose i get the simple xml sample: <foo> 1 <bar>2</bar> 3 </foo> Now suppose i want to extract all the text of only the 'foo' node, ie expected result is '1 3'. I tried both <xsl:template match="foo"> <xsl:value-of select="text()" /> </xsl:template> and <xsl:template match="foo"> <xsl:value-of select="." /> </xsl:template> but the former lead to '1' and the latter to '1 2 3' (using xsltproc & firefox). What did i missed ? thanks, -Nicolas nicolas.edel@gmail.com wrote: > Now suppose i want to extract all the text of only the 'foo' node That isn't a built-in concept; you have to recast it as "all the text nodes which are immediate children of the 'foo' node". (The built-in text value of an element, as you discovered, is the value of all text contained in it, directly or indirectly). Note too that the whitespace (line breaks and indentation) will be part of the the text nodes unless you explicitly strip that away. <xsl:value-of select="text()" /> didn't work because value-of returns the contents of only the first matching node. This is one case where xsl:for-each is appropriate, to explicitly iterate through the text children. -- Joe Kesselman / Beware the fury of a patient man. -- John Dryden On Nov 30, 12:34 am, Joseph Kesselman <kesh...

Adressing node element when parsing xml with PHP and simple XML
I need to get the elements under this XML top structure using simplexml: <PKT> - <Result Name="GetTopWinnersForLastXMinutes" Success="1"> - <Returnset> - <Winner> I am trying to get the elements, associate them in one variable and foreach them under <Winner> like this: foreach($xml->Result.Returnset.Winner as $Winner) But the resulting page is blank. Could anyone please give me a hint? On 28 Nov 2009, Nosferatum <john.olav.o@gmail.com> wrote: > I need to get the elements under this XML top structure using > simplexml: > <PKT> > - <Result Name="GetTopWinnersForLastXMinutes" Success="1"> > - <Returnset> > - <Winner> > > I am trying to get the elements, associate them in one variable > and foreach them under <Winner> like this: > foreach($xml->Result.Returnset.Winner as $Winner) foreach ($xml->Result->Returnset->Winner as $Winner) { /* ... */ } > But the resulting page is blank. Could anyone please give me a > hint? In addition to the above, you can use XPath: <?php /* instantiate a SimpleXMLElement object ... */ $result = $xml->xpath('Result/Returnset/Winner'); foreach ($result as $node) { /* ... */ } ?> -- Curtis Dyer <? $x='<? $x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?&...

Retrieving XML attribute using XML::XPath::Node::Attribute
Hi I am trying to retrieve an attribute of a particular node from my XML using "XML::XPath::Node::Attribute", but couldn't come across on how to successfully use it in my code. For example, if my xml is: <?xml version="1.0" ?> <data> <server_address port="40">10.0.0.1</server_address> </data> How do I go about fetching the "port" attribute from "server_address" element? Vikrant vikrant wrote: > > <?xml version="1.0" ?> > <data> > <server_address port="40&q...

editor for editing xml text nodes
We have xml documents which contain text imbedded as text content in some xml structures. These documents need to be translated by human translators from English into, for example, Chinese. We would like the translator to use an editor which shows him only the text content of the xml document, or gives him only editing access to the text content. The translator should be unable to touch or modify the xml tags, so that it is guaranteed that the xml-tags are unchanged when the translator returns the translated document. The translator simply replaces all English text accessible to him into Chinese text. Does anyone know an xml editing tool which has this feature, of allowing only modification to the text node content? Alois Zreindl wrote: > We have xml documents which contain text imbedded as text content in > some xml structures. > > These documents need to be translated by human translators from English > into, for example, Chinese. > > We would like the translator to use an editor which shows him only the > text content of the xml document, or gives him only editing access to > the text content. I am working on exactly this right now. It leaves the elements in element content inviolable, but allows element markup in mixed content (the only thing a translator should be touching). Please contact me by email to discuss this further. > The translator should be unable to touch or modify the xml tags, so that > it is guara...

Getting to the root node of an xml document
Hello there!I'm trying to get to an xml document root node (named dataroot), I'vetried different things, like :Node node = doc.getFirstChild();Node node = doc.getDocumentElement();Node node = doc.getElementsByTagName("dataroot").item(0);None of them seem to work, the "node" variable is NULL everytime.Here's the start of the XML file, I somebody has an idea, it's be veryhelpful :) Cheers!XML Document :<?xml version="1.0" encoding="UTF-8"?><dataroot xmlns:od="urn:schemas-microsoft-com:officedata"generated="2007-05-25...

Get xs type from xml node?
I have an xml document and an xsd. After parsing the xml document I would like to be able to get the type defined in the schema for a given node (ie: xs:string, xs:boolean, etc.). What perl modules, if any, provide this? I would think that a validating parser would have this information when it parsed it but I can't find any modules that provide this through the API. Thanks - Leo ...

How to get the value of an attribute in an XML node?
Hello, This is the url http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&retmax=10000&term=cmyc of an xml file that I am trying to read and get the values of the <IdList> node in the - <IdList> <Id>30686</Id> <Id>4609</Id> <Id>17869</Id> <Id>5728</Id> <Id>6598</Id> <Id>9111</Id> </IdList> Here is the program that I am trying to read the values of the Id in the XML file ******************************program**************************** public class EUtilParseExample { private static final String urlSearch = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?"; private static final String urlFetch = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?"; public static void main(String[] args) { InputStream input = null; try { URL u = new URL (urlSearch + "db=gene&retmax=10000&term=cmyc"); input = u.openStream(); System.out.println(u.toString()); XMLInputFactory factory = null; System.setProperty("javax.xml.stream.XMLInputFactory", "com.bea.xml.stream.MXParserFactory"); String filename = ""; //XMLInputFactory factory = XMLInputFactory.newInstance(); factory = XMLInputFactory.newInstance(); XMLEventReader r = factory.createXMLEventReader(filename, input); //iterate as long as there are more events on the input stream while(r...

Web resources about - get a xml node as-it-is - comp.text.xml

Data retention fine as it is: AFP
... proposed data retention regime would bolster evidence used to combat cybercrime, but would not add significant information that isn’t currently ...

The MacBook Air is as functional as it is a pleasure to take it on the road
The MacBook Air is as functional as it is a pleasure to take it on the road

'It is as though there were boys just on tap' - Newcastle Herald
... paedophile thought he could get away with his offending, a court has heard.

Rare earths: Rare as it is
Use China Daily website to find breaking business news headlines and articles on the economy, statistics, stock market, investing, personal finance, ...

The ‘victory’ of conservative punditry, such as it is
... safe to say conservative professional pundits have defeated their liberal counterparts," Eliana Johnson writes triumphantly in a fund-raising ...

Warren Buffett Thinks Apple's Share Buyback Is Just Fine as It Is
Berkshire Hathaway’s Warren Buffett doesn’t own any Apple shares, but if he did, he wouldn’t cast his lot with activist investor Carl Icahn, ...

The RNC’s statement on the 50th anniversary of the Voting Rights Act is as laughable as it is insulting ...
... the right to vote on arbitrary, demographic-based grounds. Of course, you could make a pretty convincing case that America still isn’t a democracy ...

Meet Fish Up: a new iOS scroller that’s as fun as it is addictive
... hook. This is harder than it might seem, however, since countless lines and barbed hooks are floating along your path. As such, you’ll need ...

Etc: Symantec is now telling customers it is safe to use pcAnywhere as long as it is updated with the ...
Symantec is now telling customers it is safe to use pcAnywhere as long as it is updated with the latest patches, days after revealing that stolen ...

E-book: Is Your Factory Floor Network as Fast as it is Reliable?
Every day, factory-floor Ethernet carry more and more critical plant and business data across industrial networks. True, EtherNet/IP is a standard,... ...

Resources last updated: 3/13/2016 9:46:24 PM