Want to maintain order of attributes using DOM
Have an XML file with this element
<Name f="", b="", e="", d="", >
i converted DOm to string using :
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
StringWriter sw = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(sw));
String stringDOM = sw.toString();
It sorts the attributes in alphabetical order. now the element looks like
<Name b="", d="", e="", f="",>
I need to maintain the order. How can i do that? Is there any way to do so?
You can't do that. XML specifically says the order of attributes doesn't matter, so if you're using a compliant parser to read the XML, you should not have to do that anyway.
Similar Messages
-
<?xml version="1.0" standalone="yes"?>
<Student_Details>
<Student Id="1">
<Name>sandeep</Name>
<Age>12</Age>
<Mobile>123456789</Mobile>
</Student>
<Student Id="2">
<Name>ololjk</Name>
<Age>kjlokmo</Age>
<Mobile>njonojniohuj</Mobile>
</Student>
<hello Id="10">
</hello>
<Student Id="3">
<Name>Sandeep Pr</Name>
<Age>12</Age>
<Mobile>9865231870</Mobile>
</Student>
<Student Id="4">
<Name>ololjk</Name>
<Age>kjlokmo</Age>
<Mobile>njonojniohuj</Mobile>
</Student>
all i can fount in internet is which will not display the attributes so pls upload a proper code which also creates an attribute node???
Sandeep PuvvadiEnumerate your XML using
XDocument. For each element
Generate a new TreeNode with whatever text you want to show
Insert the node into your tree
Enumerate all the attributes of the element using the
Attributes() method
Insert a child node of the element node for each attribute with whatever text you want to show
Note that your XML is not valid. You have a <hello> element in the middle of it and the root element is not closed. You'll need to fix that before the XML can be parsed.
Michael Taylor
http://blogs.msmvps.com/p3net -
Sample java code which reads xml attributes using DOM Parser
Hi Friends,
I am looking for a sample java code which uses the DOM Parser to read the attributes values.
My xml looks like below
<?xml version='1.0' encoding='UTF-8'?>
<root>
<header unid="100" status="true">
<validation stage="1" processed="10"/>
</header>
</root>
Experts please help...
Thanks in Advance
JJYou have probably found lots of resources on the www for this by now, if not: [http://www.w3schools.com/dom/default.asp|http://www.w3schools.com/dom/default.asp]
-
Problem in parsing JMS TextMessages using DOM
Hi
I want to parse JMS TextMessages by using DOM parser.DomBuilder's parse method supports only Strings,input stream in its constructor.
Is there anyway we can parse JMS TextMessages by using DOM.Your help would be appreciated.
Thanks
Kanthkanth218 wrote:
Hi
DomBuilder's parse method supports only Strings,input stream in its constructor.This is not true. Have another look at the documentation.
Is there anyway we can parse JMS TextMessages by using DOM.Your help would be appreciated.
parse(new InputSource(new StringReader(someString))) -
If you are not using J2SE 1.4 - OrderedMap - (maintains order of insertion)
Hi,
If you are not using J2SE 1.4 and still want to maintain the order of insertion unlike HashMap or Hashtable(which doesn't allow)
OrderedMap comes to resue!
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
public final class OrderedMap extends TreeMap {
private List list= new ArrayList();
public OrderedMap() {
public Object put(Object key, Object value) {
list.add(key);
return super.put(key, value);
public List getKeysList() {
return list;
};;Mail me how to use it!
Bye
tuniki
[email protected]Hi, Dude!
Probably you have to read the subject b4 posting something!
(Re: If you are not using J2SE 1.4 ->OrderedMap ->(maintains order of insertion))
Tuniki
[email protected] -
Problem in parsing XML using DOM Parser.
Hi,
I am parsing an XML using DOM Parser.
When i try to get attributes of a node, i dont get in the order it is written. For Eg. This the node:
<Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa">
When i try to print the attribute values i should get in the order:
News, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, 202, COGN-4MNMT3, aaaa
BUT I AM GETTING IN THE ORDER:
News, 202, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, aaaa, COGN-4MNMT3
Is there any way to sort this problem out?
Thanks and Regards,
AshokHi Guys,
Thanks a lot for your replies.
But i want to keep all the values as attributes only.
the XML file is as shown below:
<Menu>
<Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa" children="3">
<Level1 label="ING News" link="" level="1" uid="COGN-4MNN89" parentid="COGN-4MNMT3" children="3" >
<Level2 label="All ING News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="2" uid="INGD-4MVTK2" parentid="COGN-4MNN89" children="0">
</Level2>
</Level1>
</Level0>
The code i was using to get attributes is:
String strElementName = new String(node.getNodeName());
// System.out.println("strElementName:"+node.getNodeName());
NamedNodeMap attrs = node.getAttributes();
if (attrs != null) {
int iLength = attrs.getLength();
for (int i = 0; i < iLength; i++) {
String strAttributes = (String) attrs.item(i).getNodeName();
String strValues = (String) attrs.item(i).getNodeValue();
Also is it not possible to Enforce the order using some Schema/DTD in this case?
TIA
Ashok -
How create a purchase order without imputation using bapi: BAPI_PO_CREATE1
Hello Forum
I have an request for purchase order with imputation K (cost center, EBAN-KNTTP). During the liberation of the request for purchase order, and using the Bapi: BAPI_PO_CREATE1, I want to create a Purchase Order without imputation (imputation empty or charge empty).
The system displays the following error: The request for purchase order, item (position) 10, is attributed to another order...
I imagine that is because the request for purchase order has imputation (charged) K and the purchase order will have no type of imputation (imputation empty).
However, manually, Yes, I can create the purchase order. That is, I first release, the request for purchase order. Then I create the order of purchase using ME21 and with reference to request for purchase order, and when SAP returns the items of the request for purchase order, I manually remove the imputation K, and these items to become the purchase order.
Please support me want to know how to resolve this case, why can not I create a purchase order without imputation to from the request for purchase order with imputation K, using Bapi
Thank you.
Greetings,Hi,
In the item overview of the purchase order creation screen (ME21N), you have a column Purchasing Doc and next it item no. You can give the existing purchase order number here with item no which will create a purchase order, and changes can be made wherever you require.
Hope this helps.
Thanks
Krishna. -
Need to retrieve all the node values of xml using DOM parser..pls help
I want to fetch each node value in this xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Main>
<AAAAA>
<ES>ESValue</ES>
<EI>EIValue</EI>
</AAAAA>
<BBBBB>
<SIP>
<ST>STValue</ST>
<TB>TBValue</TB>
<PM>PMValue</PM>
<VIP>
<CARP>
<AN1>AN1Value</AN1>
<BN>BNValue</BN>
</CARP>
<DARP>
<SA>
<AN2>AN2Value</AN2>
<CN>CNValue</CN>
</SA>
</DARP>
</VIP>
</SIP>
</BBBBB>
</Main>
output should be the inner text values of diffrent nodes that contain some values..
i.e
output:
ESValue
EIValue
STValue
TBValue
PMValue
AN1Value
BNValue
AN2Value
CNValue
so that i can use thses node values and put it them in database...pls check the above xml file in proper redable order...I need to parse using DOM and fetch node values that are present...
<?xml version="1.0" encoding="UTF-8"?>
<Main>
<AAAAA>
<ES>ESValue</ES>
<EI>EIValue</EI>
</AAAAA>
<BBBBB>
<SIP>
<ST>STValue</ST>
<TB>TBValue</TB>
<PM>PMValue</PM>
<VIP>
<CARP>
<AN1>AN1Value</AN1>
<BN>BNValue</BN>
</CARP>
<DARP>
<SA>
<AN2>AN2Value</AN2>
<CN>CNValue</CN>
</SA>
</DARP>
</VIP>
</SIP>
</BBBBB>
</Main> -
Internet Sales Order - Additional attributes
Hi,
I have a requirement to enable Certification Requirements for products being sold. Process goes like this -
Customer places a Sales Order on Internet via Internet Sales Solution. While placing the order, customer would select the types of certifications required for the product for example: certificate on country of origin, Quality certificate etc. User should be able to select multiple such certificates as required, while creating the Sales Order. Is there any way I can achieve this? I am thinking about using additional attributes (via Set Types and attributes) assigned to the product master. But, by assigning these to the product master, can I see the same attirbutes in the Sales Order in Internet Sales? Secondly, can these attributes (with values) be transferred back to R/3 Sales Order? Any suggestions will be appreciated and properly rewarded for good answers.
Thanks in advanceHi Gopala,
Yes. You can use additional products attributes to display the required certification parameters.
But these attributes can't be transfered onto the sales order by default. You need to some java development / abap development to extend the sales order.
If you want to transfer the same attributes to R/3 order then you have enhance the BAPIMATICS strucuture so that the middleware transfers them.
Also you need to extend R/3 sales order to hold these attributes. This is a complex scenario and you need to design a good functional specification document before even attempting the design
Let me know, if you need any further info.
<b>
Do not forget to reward if it helps,</b>
Regards,
Paul Kondaveeti -
Order of Attributes in InfoWindow and Dynamic Pies
I use the following SQL select in a JDBC Query:
SELECT o.geom, k.kundennummer, a.NAME Name, a.STRASSE Straße, a.LAND || '-' || a.PLZ || ' ' || a.ORT Ort, '', d.SALDO || ' EUR' Umsatz
I'm trying to use this sql select for two things:
1. Showing a InfoWindow with all of the attributes (in this specific order)
2. Use the column 'Umsatz' for a dynamic pie.
Unfortunately the dynamic pie always use the column kundennummer. Ok, if I will change the order of the column in the select statement, the pie uses the correct column, but that is not the order I want to use in the InfoWindow.
Another problem is that the pie can't use the composited column 'Umsatz' at all. Or I am wrong?
Best regards,
MichaelCheck the link
Oracle Maps - MVPieChartStyle example
maybe you can get additional information's.
I think the pie Column is configurable in the code by using the parameter label_column.
Try it. -
List of SQL tables and attributes used in SSRS reports
Hi,
I have around 450-500 reports deployed in SSRS reporting server.
All these reports are built on SQL from multiple databases, and these databases are having unnecessary tables and attributes.
My requirement is to clean the unused tables and attributes from the databases. For this, I need the list of SQL tables and attributes used in these 450-500 SSRS reports.
Is there any way to get this data?
Regards,
RKHi RK,
According to your description, you want to get a list of the tables and attributes used in all reports.
In your scenario, you can query the ReportServer.dbo.Catalog table to get Report name, data source name, dataset name, and query used in the dataset with query below:
WITH XMLNAMESPACES ( DEFAULT 'http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition', 'http://schemas.microsoft.com/SQLServer/reporting/reportdesigner' AS rd )
SELECT ReportName = name
,DataSetName = x.value('(@Name)[1]', 'VARCHAR(250)')
,DataSourceName = x.value('(Query/DataSourceName)[1]','VARCHAR(250)')
,CommandText = x.value('(Query/CommandText)[1]','VARCHAR(250)')
,Fields = df.value('(@Name)[1]','VARCHAR(250)')
,DataField = df.value('(DataField)[1]','VARCHAR(250)')
,DataType = df.value('(rd:TypeName)[1]','VARCHAR(250)')
--,ConnectionString = x.value('(ConnectionProperties/ConnectString)[1]','VARCHAR(250)')
FROM ( SELECT C.Name,CONVERT(XML,CONVERT(VARBINARY(MAX),C.Content)) AS reportXML
FROM ReportServer.dbo.Catalog C
WHERE C.Content is not null
AND C.Type = 2
) a
CROSS APPLY reportXML.nodes('/Report/DataSets/DataSet') r ( x )
CROSS APPLY x.nodes('Fields/Field') f(df)
ORDER BY name
For more information, please refer to this similar thread:
Extract metadata from report server database
If you have any question, please feel free to ask.
Best regards,
Qiuyun Yu
Qiuyun Yu
TechNet Community Support -
Namespace declaration using DOM
Hi,
I am using DOM to create an XML document. How do I declare namespace?
I want to know which API is used to create namespace declaration in an XML document.
I want my final XML document to be
<RootElement xmlns:c="http://pradeep.somesite.com">
<name>pradeep</name>
<RootElement>
My problem is how to put the xml ns declaraton in RootElement.
Some one plz help;
thanks in adv.xmlns is like any other attribute.
Try something like:
NamedNodeMap attributes = rootElement.getAttributes();
Attr namespace = myDoc.createAttribute("xmlns");
namespace.setValue("........");
attributes.setNamedItem(namespace); -
How to manipulate object mapping runtime using DOM parser in java?
Scenario: We will be getting logical name of the table from which we have to fetch the details. We have few tables which have more or less same columns, the only difference is the prefix. Say we have Tables: Temp1 and Temp2 contains column as Temp1Col1 and Temp2Col1. I dont want to go with creating as many POJO classes in java as that of tables. So i will create only one POJO class with common attributes and at runtime i want to change the object mapping file of Hibernate to hold table values. I have an idea that this can be done using DOM parser. But it would be great if somebody can share the java code for the same.
Thanks in advance.SAX is a parser, not a generator.Well,
you can use it to create an XML file too. And it will take care of proper encoding, thus being much superior to a normal textwriter:
See the following code snippet (out is a OutputStream):
PrintWriter pw = new PrintWriter(out);
StreamResult streamResult = new StreamResult(pw);
SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
// SAX2.0 ContentHandler.
TransformerHandler hd = tf.newTransformerHandler();
Transformer serializer = hd.getTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//
serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"pdfBookmarks.xsd");
serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"http://schema.inplus.de/pdf/1.0");
serializer.setOutputProperty(OutputKeys.METHOD,"xml");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
hd.setResult(streamResult);
hd.startDocument();
//Get a processing instruction
hd.processingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"mystyle.xsl\"");
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "someattribute", "CDATA", "test");
atts.addAttribute("", "", "moreattributes", "CDATA", "test2");
hd.startElement("", "", "MyTag", atts);
String curTitle = "Something inside a tag";
hd.characters(curTitle.toCharArray(), 0, curTitle.length());
hd.endElement("", "", "MyTag");
hd.endDocument();
You are responsible for proper nesting. SAX takes care of encoding.
Hth
;-) stw -
Ordering fields displayed using af:query
Hi All,
I want to order the query fields on the search form. The search form was created by dragging a af:query component in JDeveloper11.1.1.4
Basically I want to show the "Key" before "Given name" and "family Name". Looks like the af:query orders the query fields alphabetically.
I also tried using the field order property of the view object attribute, but no success. Please suggest.
ThanksHi Frank,
I mentioned in my previous post, even after using the 'Field Order' property in the view object's attribute, I was not able to move the 'Key field in the query to the top.
Is there any other Field Order property?
I am using the <viewobject>.xml then go the appropriate attribute and under UI Hints in the Property Inspector put 1 in the 'Field Order' Property attribute. Other fields are all default blank for Field Order
Does not work for me, please suggest
Thanks
Edited by: user5108636 on Nov 8, 2011 8:17 PM -
I want to extract the Solaris media using "unpackmedia" option
pack and unpack options operates on only miniroot archives and not on whole Solaris media.
I want to extract the Solaris media using "unpackmedia" option.
unpackmedia option of root_archive internally extract miniroots and additionally it extracts X.cpio.bz2 and pkg_db.cpio.bz2 based on some manipulations.
man page of root_archive on solaris 11 still shows the information about these two removed options.
Please let me know is there other way to achieve operations same as provided by unpackmedia option?
Regards,
UmeshWhen you intermix java/javascript code like this you have to realise the order in which this occurs.
1 - all java code is executed - produces a static html
2 - html is loaded, and javascript is run.
So you can't run java code from an onClick event on the page.
You have to submit a request (ie submit form/click link) to run java code, and it sends a response (new page) to the browser.
So what you would end up with is code like this on your page
Assuming you have three items in your list: {Item0, Item1, Item2} this will be the result:
var z=0
// for item0
c.options[z]=new Option("Name0",Id0)
z++
c.options[z]=new Option("Name1",Id1)
// for item1
c.options[z]=new Option("Name0",Id0)
z++
c.options[z]=new Option("Name1",Id1)
// for item2
c.options[z]=new Option("Item0",Item0)
z++
c.options[z]=new Option("Item1",Item1)Suggestions as to what is wrong with this code
1 - you only increment z once on each loop, but save two items.
2 - you aren't using your counter 'I' in the get method.
3 - you might need quotes around the values as well as the names.
Personally, I think you're going the entire wrong way about this.
Should you be using public static variable attributes? Are these values to be the same for every single user in the system?
I would prefer to use a jsp scope (application scope if it is for all users) and just generate the html for the select right onto the page, rather than generating javascript to run and build the list.
I would also use JSTL
ie
<select name="mySelect>
<c:forEach var="asset" items="${assetList}">
<option value="${asset.id}"><c:out value="${asset.name}"/>
</c:forEach>
</select>
Maybe you are looking for
-
Volume controls on my Apple BT Keyboard do not control volume on my Mac Mini
I just updated the OS on my Mac Mini to Yosemite and everything was working fine, but earlier today the volume control buttons on my Apple BT Keyboard stopped controlling the volume on my Mac Mini. I was watching a movie just last night and the keybo
-
Keeps telling me that I have an invalid Serial Number during update
Trying to update and download Acrobat 8.0 to 8.1.0 and keeps telling me have invalid serial number when software is active and working on my computer.
-
Cannot download latest update...help?
I can download the update but as soon as I hit "run" a dialogue box appears that says "Instalshield" in the top left corner and then has a bunch of command line perameters with an "ok" button at the button...I hit ok and nothing happens...help?
-
About migrating from 10.1.2 to 10.1.3 (page events)
Hi forum, As authentication based on public key certificates only works under jdev 10.1.3.1, I'm upgrading my 10.1.2 application to that version. I'm following the Oracle document "Converting to the ADF Page Lifecycle from 10.1.2" (http://www.oracle.
-
How do I recover NOTES that were deleted
Can I recoved NOTES that were deleted?