senjuhashirama / pugixml

Automatically exported from code.google.com/p/pugixml
0 stars 0 forks source link

Update Document #179

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am creating new document. Adding cloned node of the existing document. It is 
done successfully. But when i make changes in the cloned node, new document 
does not change. 
Please help me.
Kshitija

Original issue reported on code.google.com by kshitija...@gmail.com on 28 Sep 2012 at 5:39

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
How to set namespace for existing xml document?

I am trying to load following xml string but it fails:
<?xml version="1.0" encoding="utf-8"? >
<test:testnodes xmlns:test="http://test.com/">
  <test:nodecategory1>
    <test:node attribute1="valueA" attribute2="valueB" attribute3="valueC">nodevalue1</test:node>
  </test:nodecategory1>
  <test:nodecategory2>
    <test:node attribute1="valueD" attribute2="valueE" attribute3="valueF">nodevalue2</test:node>
      <test:node attribute1="valueG" attribute2="valueH\" attribute3="valueI">nodevalue3</test:node>
  </test:nodecategory2>
  <test:nodecategory3>
    <test:node attribute1="valueJ" attribute2="valueK" attribute3="valueL">nodevalue4</test:node>
  </test:nodecategory3>
</test:testnodes>

I am using load_buffer method
load_buffer(xmlData.c_str(), xmlData.size() * sizeof(wchar_t), 0, 
pugi::encoding_wchar);

but it is not correctly loading the document. I want to load the string as it 
is in to buffer.
I tried to get particular node from this xml using xpath but fails. how to 
implement that?

Kshitija

Original comment by kshitija...@gmail.com on 28 Sep 2012 at 9:55

GoogleCodeExporter commented 9 years ago
Please provide code examples for the cloning issue (i.e. how you're cloning the 
node and how you're changing it). What does "is not correctly loading the 
document" mean exactly? What xpath were you using and how?

Original comment by arseny.k...@gmail.com on 29 Sep 2012 at 5:58

GoogleCodeExporter commented 9 years ago
Now it is loading the dicument correctly. There was error in xml string only. 

For setting the namespace i am using following code

CXmlDocument::SetNamespace(const std::wstring& selectionNamespace)
{
   pugi::xml_node child_node;
   pugi::xml_attribute attr;

   child_node = m_XmlDocument.first_child();
   attr = child_node.append_attribute("xmlns");
   attr.set_value(selectionNamespace);

   return OK;
} 

Is it correct? If namespace is set for document already then this code will 
work or not?

Kshitija

Original comment by kshitija...@gmail.com on 1 Oct 2012 at 4:52

GoogleCodeExporter commented 9 years ago
This code will append an attribute even if there is one. A better alternative 
is something like this:

attr = child_node.attribute("xmlns");
if (!attr) attr = child_node.append_attribute("xmlns");
attr.set_value(pugi::as_utf8(selectionNamespace).c_str());

Original comment by arseny.k...@gmail.com on 1 Oct 2012 at 3:07

GoogleCodeExporter commented 9 years ago

Original comment by arseny.k...@gmail.com on 11 Oct 2012 at 4:43