Modifying an XML in Java -


I have an XML document that has zero values ​​in its value tag (something like the following)

< Pre> and lieutenant; NS2: Attribute Name = "Store" Named Format = "Kalash: Oasis: Name: TC: SAM: 2.0: Attiname-Format: Yuri" & gt; & Lt; Ns2: AttributeValue / & gt; & Lt; / Ns2: Properties & gt;

Now, I have to write the Java code to modify the values ​​given below.

  & lt; Ns2: attribute name = "store" nameFormat = "vase: oasis: name: tc: SAML: 2.0: attrname format: uri" & gt; & Lt; Ns2: AttributeValue & gt; ABCDEF & lt; / Ns2: AttributeValue & gt; & Lt; / Ns2: Properties & gt;  

I am using the DOM parser to parse the XML. I am able to delete the "tap tag" but not able to add new values. I'm not sure that we have a direct way to change or add values.

Using the code to remove the child ("")

  node aNode = nodelist.itim (i); element = (allment) annotated; ehelment. Review chaled (eelament.tafert Child (). GetNextSibling ());  

Thanks in advance

Just add the data through setTextContent sample code below:

  public static void main (String [] args) IOException, SAXException, ParserConfigurationException, TransformerException {string xml = "& lt; Ns2: Attribute name = \ "throws store \" NameFormat = \ "vase: oasis: name: tc: SAML: 2.0: attrname-format: yuri \" & gt; & Lt; Ns2: attributeValue / & gt; & Lt; / Ns2: attribute & gt; "; DocumentBuilderFactory dbFactory = DocumentBuilderFactory new Instrens (); Dastavejhbilder Dibilder + dbFactory.newDocumentBuilder (); Document d'Oc = dBuilder.parse (new Baitareinputstrym (XmlkgetBytes ())); DockgetDocumentElement ( ) normal () .; node list nList = doc.getElementsByTagName ( "nS 2: Attribud value"); and (int i = 0; i & lt; nList.getLength (for); i ++) {Element Emil = ( Element) nList.item (i); elem.setTextContent ("content" + i);} transformerformer transformerfactor = transformerfactor.NewInstance (); Ransfarmr transformer = Tronsfarmrfaccr. Nav Transformers (); DOMSource source = new DOMSource (doctor); StreamResult results = new Stream Result (System.out); transformers. Transform (source, result); Println (nList.getLength ());}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -